lau*_*one 5 iphone uilabel ios swift uifontdescriptor
我目前正在创建扩展,UILabel
以方便观察动态类型。一旦UIContentSizeCategoryDidChangeNotification
收到,我想我的选择通过使用设置标签的字体
self.font = UIFont.preferredFontForTextStyle(someUIFontTextStyle)
Run Code Online (Sandbox Code Playgroud)
其中,someUIFontTextStyle
使用相同的UIFontTextStyle
标签目前呈现。我曾希望可以通过类似这样的属性来访问这样的属性self.font.fontDescriptor.textStyle
,但事实似乎有点令人费解。
有没有办法访问与UIFontTextStyle
关联的属性UILabel
?
self.font.fontDescriptor().objectForKey(UIFontDescriptorTextStyleAttribute) as? String
Run Code Online (Sandbox Code Playgroud)
接受的答案对于 swift 3 来说不太正确。 UIContentSizeCategoryDidChangeNotification的处理程序需要执行以下操作:
if let font = myUILable.font.fontDescriptor.object(forKey: UIFontDescriptorTextStyleAttribute) as? UIFontTextStyle {
myUILabel.font = UIFont.preferredFont(forTextStyle: font)
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1339 次 |
最近记录: |