如何在iOS故事板中使用自定义字体来表示动态类型辅助功能大小 [英] How to honor Dynamic Type Accessibility Sizes with a custom font in an iOS storyboard
问题描述
如何使用
虽然您无法同时指定自定义字体和通过Storyboard首选文本样式,以编程方式为自定义字体指定动态类型大小并不困难:
let pointSize = UIFontDescriptor .preferredFontDescriptorWithTextStyle(UIFont TextStyleTitle1).poi ntSize
let customFont = UIFont(name:Chalkboard SE,size:pointSize)
当您收到 UIContentSizeCategoryDidChangeNotification
时,请使用相同的代码更新标签的字体。
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 Type size in iOS (Apple has been encouraging this since iOS 7?) I also need to use the built-in font Chalkboard SE, which is not used by default for the "text styles" fonts. I am currently using a custom font as shown in the image, but need the font to change size in accordance with the user's Dynamic Type/Accessibility Sizes preference just as all the Text Styles fonts do. The best Text Styles option is Title 1, but the font/typeface is unacceptable.
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:
let pointSize = UIFontDescriptor.preferredFontDescriptorWithTextStyle(UIFontTextStyleTitle1).pointSize
let customFont = UIFont(name: "Chalkboard SE", size: pointSize)
When you receive a UIContentSizeCategoryDidChangeNotification
, use the same code to update your label's font.
这篇关于如何在iOS故事板中使用自定义字体来表示动态类型辅助功能大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!