30

如何preferredFontForTextStyle为每个Text 样式返回自定义 UIFont ?

例如,我想使用 ArialHebrew-Bold 字体UIFontTextStyleHeadline并使用 ArialHebrewUIFontTextStyleBody

4

3 回答 3

41

如果您只是喜欢使用自己的字体的动态字体大小,您可以这样做

UIFontDescriptor *userFont = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleBody];
float userFontSize = [userFont pointSize];
UIFont *font = [UIFont fontWithName:@"ArialHebrew-Bold" size:userFontSize];
于 2013-10-02T09:05:24.113 回答
9

斯威夫特的版本:

let systemDynamicFontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .body)
let size = systemDynamicFontDescriptor.pointSize
let font = UIFont(name: "ArialHebrew-Bold", size: size)
于 2015-08-14T04:24:00.577 回答
6

从 iOS 11 开始:

let bodyMetrics = UIFontMetrics(forTextStyle: .body)
let standardFont = ... // any font you want, for standard type size
let font = bodyMetrics.scaledFont(for: standardFont)
于 2017-08-15T08:17:41.257 回答