Custom UIFont for preferredFontForTextStyle

Swift's version:

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

If you just like dynamic font-size with your own font you can do this

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

Starting with iOS 11:

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

Tags:

Ios