如何從preferredFontForTextStyle
中爲每個文本樣式返回一個自定義UIFont?自定義UIFont for preferredFontForTextStyle
如 我想用ArialHebrew粗體字體爲UIFontTextStyleHeadline
和使用ArialHebrew爲UIFontTextStyleBody
如何從preferredFontForTextStyle
中爲每個文本樣式返回一個自定義UIFont?自定義UIFont for preferredFontForTextStyle
如 我想用ArialHebrew粗體字體爲UIFontTextStyleHeadline
和使用ArialHebrew爲UIFontTextStyleBody
如果你只是喜歡動態字體大小與自己的字體,你可以做到這一點
UIFontDescriptor *userFont = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleBody];
float userFontSize = [userFont pointSize];
UIFont *font = [UIFont fontWithName:@"ArialHebrew-Bold" size:userFontSize];
斯威夫特的版本:
let systemDynamicFontDescriptor = UIFontDescriptor.preferredFontDescriptorWithTextStyle(UIFontTextStyleBody)
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)
真棒夥計..謝謝 – shyamsundar1988