How to use a custom font with dynamic text sizes in iOS7

前端 未结 12 2106
长情又很酷
长情又很酷 2020-11-29 14:41

In iOS7 there are new API\'s for getting a font that is automatically adjusted to the text size the user has set in their preferences.

It looks something like this to

12条回答
  •  不知归路
    2020-11-29 15:35

    In iOS 11 UIFontMetrics class was introduced. Create a FontMetrics object for the text style that you're interested in. Then choose any font you want, sized for the standard dynamic type size. And then you can ask the FontMetrics object to scale that font given the user's current settings.

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

提交回复
热议问题