如何preferredFontForTextStyle
为每个Text 样式返回自定义 UIFont ?
例如,我想使用 ArialHebrew-Bold 字体UIFontTextStyleHeadline
并使用 ArialHebrewUIFontTextStyleBody
如何preferredFontForTextStyle
为每个Text 样式返回自定义 UIFont ?
例如,我想使用 ArialHebrew-Bold 字体UIFontTextStyleHeadline
并使用 ArialHebrewUIFontTextStyleBody
如果您只是喜欢使用自己的字体的动态字体大小,您可以这样做
UIFontDescriptor *userFont = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleBody];
float userFontSize = [userFont pointSize];
UIFont *font = [UIFont fontWithName:@"ArialHebrew-Bold" size:userFontSize];
斯威夫特的版本:
let systemDynamicFontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .body)
let size = systemDynamicFontDescriptor.pointSize
let font = UIFont(name: "ArialHebrew-Bold", size: size)
从 iOS 11 开始:
let bodyMetrics = UIFontMetrics(forTextStyle: .body)
let standardFont = ... // any font you want, for standard type size
let font = bodyMetrics.scaledFont(for: standardFont)