首页 > 移动平台 > 详细

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

时间:2015-02-05 20:06:27      阅读:337      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!