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

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

时间: 2024-08-09 10:33:51

Big Nerd iOS Programming 第20章 Dynamic Type 动态类型的相关文章

Big Nerd iOS Programming 第21章 Web service ,UIWebView

1. 两部分: 链接并获取数据 从获取到数据构建数据模型 2.通过HTTP协议于web服务器通信 `浏览器发送一个请求给制定的url地址,url返回求情页.HTML以及图片 `浏览器发生带有其他参数的比如是表数据 给制定的服务器,服务器返回一个自定义的或者动态的活着web page 3.数据格式一般是JSON或者XML 4.请求的url格式. 一般没有特定的格式,只要服务器能识别即可.比如灰腾腾p://bookapi.bignerdranch.com/course.json http://bas

dynamic:动态类型简单用法,写法

class 动态创建数据 { //动态类型:本质感觉跟object的用法差不多,只是在执行的时候才知道数据类型 public dynamic Dynamic() { //定义一个动态类型,作为返回值 dynamic data = new ExpandoObject(); List<dynamic> list = new List<dynamic>(); dynamic model = new ExpandoObject(); model.ID = 1; model.Name = &

Dynamic typing 动态类型

https://developer.apple.com/library/content/documentation/General/Conceptual/DevPedia-CocoaCore/DynamicTyping.html#//apple_ref/doc/uid/TP40008195-CH62-SW2 A variable is dynamically typed when the type of the object it points to is not checked at comp

第9章 多态、动态类型和动态绑定(Objective-C 程序设计)

9.1 多态:相同的名称,不同的类 使不同的类共享相同方法名称的能力称为多态.它让你可以开发一组类,这组类中的每一个类都能响应相同的方法名.每个类定义都封装了特定方法所需的代码,这就使得它独立于其他的类定义. 9.2 动态绑定和id类型 id数据类型可以存储属于任何类的对象. 1 id dataValue; 2 3 Fraction *f1 = [[Fraction alloc] init]; 4 Complex *c0 = [[Complex alloc] init]; 5 6 dataVal

c# dynamic动态类型和匿名类(转)

简单示例 dynamic expando = new System.Dynamic.ExpandoObject(); //动态类型字段 可读可写 expando.Id = 1; expando.Name = "Test"; string json = Utils.ConvertJson.JsonEncode(expando); //输出{Id:1,Name:'Test'} //动态添加字段 List<string> fieldList = new List<strin

c# dynamic动态类型和匿名类

dynamic类型简单示例 dynamic expando = new System.Dynamic.ExpandoObject(); //动态类型字段 可读可写 expando.Id = 1; expando.Name = "Test"; string json = Utils.ConvertJson.JsonEncode(expando); //输出{Id:1,Name:'Test'} 动态添加字段 List<string> fieldList = new List&l

iOS Programming Dynamic Type 1

iOS Programming Dynamic Type 1? Dynamic Type is a technology introduced in iOS 7 that helps realize this goal by providing specifically designed text styles that are optimized for legibility. Dynamic Type 是从iOS7引入的技术来帮助实现这个目标通过提供专门设计的text styles 为了优化

iOS Programming The Big Nerd Ranch Guide (4th Edition)

Book Description Updated and expanded to cover iOS 7 and Xcode 5, iOS Programming: The Big Nerd Ranch Guide leads you through the essential concepts, tools, and techniques for developing iOS applications. After completing this book, you will have the

iOS Programming UIStoryboard 故事板

iOS Programming UIStoryboard In this chapter, you will use a storyboard instead. Storyboards are a feature of iOS that allows you to instantiate and lay out all of your view controllers in one XIB-like file. Additionally, you can wire up view control