How to honor Dynamic Type Accessibility Sizes with a custom font in an iOS storyboard

后端 未结 3 739
我在风中等你
我在风中等你 2021-02-19 07:27

How can I use the dynamic type text style \"Title 1\" and set the font face to the built-in font Chalkboard SE for a UILabel in a storyboard?

I need to honor the Dynamic

3条回答
  •  迷失自我
    2021-02-19 07:48

    Although you can't specify both a custom font and a preferred text style via Storyboard, it's not difficult to programmatically specify a dynamic type size for your custom font:

    Swift:

    let pointSize  = UIFontDescriptor.preferredFontDescriptorWithTextStyle(UIFont‌​TextStyleTitle1).poi‌​ntSize
    let customFont = UIFont(name: "Chalkboard SE", size: pointSize)
    

    When you receive a UIContentSizeCategoryDidChangeNotification, use the same code to update your label's font.

    Obj C:

     CGFloat pointSize = [[UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleHeadline] pointSize];
     [titleLabel setFont:[UIFont fontWithName:@"Marker Felt" size:pointSize]];
    

提交回复
热议问题