Подтвердить что ты не робот

Пользовательский UIFont для preferredFontForTextStyle

Как я могу вернуть пользовательский UIFont из preferredFontForTextStyle для каждого стиля текста?

например Я хочу использовать шрифт ArialHebrew-Bold для UIFontTextStyleHeadline и использовать ArialHebrew для UIFontTextStyleBody

4b9b3361

Ответ 1

Если вам просто нравится динамический размер шрифта со своим собственным шрифтом, вы можете сделать это

UIFontDescriptor *userFont = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleBody];
float userFontSize = [userFont pointSize];
UIFont *font = [UIFont fontWithName:@"ArialHebrew-Bold" size:userFontSize];

Ответ 2

Swift версия:

let systemDynamicFontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .body)
let size = systemDynamicFontDescriptor.pointSize
let font = UIFont(name: "ArialHebrew-Bold", size: size)

Ответ 3

Начиная с iOS 11:

let bodyMetrics = UIFontMetrics(forTextStyle: .body)
let standardFont = ... // any font you want, for standard type size
let font = bodyMetrics.scaledFont(for: standardFont)