码迷,mamicode.com
首页 > 移动开发 > 详细

Big Nerd iOS Programming 第20章 Dynamic Type 动态类型

时间:2015-02-05 20:09:00      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

Dynamic Type 动态类型

1.比如字体。使用动态的用户自定义的系统字体。

    -(void)updateFonts
    {
        UIFont *font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
        self.nameLabel.font = font;
        self.dataLabel.font = font;
    }

2.注册,获取修改通知
    当用户修改了字体或者系统设置,会发送一个消息,UIContentSizeCategoryDidChangeNotification
    //....
    NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
    [defaultCenter addObserver:self
                    selector:@selector(updateFonts:)
                    name:UIContentSizeCategoryDidChangeNotification
                    object:nil];

    !!!注意,记得移除
    -(void)dealloc
    {
        NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
        [defaultCenter removeObserver:self];
    }

3.重新设置布局
    intrinsicContentSize
    nameLabel.leading = superview.leading + 8
    nameField.leading = nameLabel.trailing + 8
    nameField.trailing = superview.trailing - 8

4.获取用户设置的字体大小,更改单元格的高度
    -(void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
        [self updateTableViewForDynamicTypeSize];
    }
    -(void)updateTableViewForDynamicTypeSize
    {
        static NSDictionary *cellHeightDicrionary;
        if(!cellHeightDicrionary){
            cellHeightDictionary = @{ UIContentSizeCategoryExtraSmall : @44,
                                  UIContentSizeCategorySmall : @44,
                                  UIContentSizeCategoryMedium : @44,
                                  UIContentSizeCategoryLarge : @44,
                                  UIContentSizeCategoryExtraLarge : @55,
                                  UIContentSizeCategoryExtraExtraLarge : @65,
                                  UIContentSizeCategoryExtraExtraExtraLarge : @75 };
        }
        NSString *userSize = [[UIApplication sharedApplication] preferredContentSizeCategory];
        NSNumber *cellHeight = cellHeightDicrionary[userSize];
        [self.tableView setRowHeigt:cellHeight.floatValue];
        //然后再加载数据
        [self.tableView reloadData];
    }

5.Updating BNRItemCell
    
    awakeFromNib

    Constraint outlets

    Placeholder constraints   

Big Nerd iOS Programming 第20章 Dynamic Type 动态类型

标签:

原文地址:http://www.cnblogs.com/wuyr/p/4275460.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!