LoginSignup
17
17

More than 5 years have passed since last update.

UIFontの標準サイズを調べた + Dynamic Typeについて

Last updated at Posted at 2017-07-03

公式ドキュメント

基本ここに書いてある
https://developer.apple.com/ios/human-interface-guidelines/visual-design/typography/

systemFont

フォントサイズを決める参考に、UIFont.systemFontSizeが実際どんなサイズか気になったので、Simulatorで調査しました。

調査方法

2017/5/25時点
Simulatorの各端末
iOS 10.3
設定は標準設定です

調査コードは以下の通りです。

import UIKit

class ViewController: UIViewController {
    let deviceName = "iPhone 7"
    override func viewDidLoad() {
        super.viewDidLoad()
        print("|\(deviceName)|\(UIFont.systemFontSize)|\(UIFont.smallSystemFontSize)|\(UIFont.labelFontSize)|\(UIFont.buttonFontSize)|")
    }
}

調査結果

機種名 systemFontSize smallSystemFontSize labelFontSize buttonFontSize
iPhone 5 14.0 12.0 17.0 18.0
iPhone 6s 14.0 12.0 17.0 18.0
iPhone 7 14.0 12.0 17.0 18.0
iPhone 7 Plus 14.0 12.0 17.0 18.0
iPhone SE 14.0 12.0 17.0 18.0

端末によっては変わらないですね。
設定のアクセシビリティから文字サイズを変更しても変わりません。

これに追従させるには、DynamicTypeに対応させる必要があります。

DynamicType

設定画面で設定できる文字サイズに対応させることができます。

label.font = UIFont.preferredFont(forTextStyle: .headline)
label.adjustsFontForContentSizeCategory = true

のようにして対応させます。
.adjustsFontForContentSizeCategory は設定の変更を監視して即時反映させる設定です。

not larger text larger text
Simulator Screen Shot 2017.05.25 15.06.46.png Simulator Screen Shot 2017.05.25 15.07.40.png

最小を1として

通常1〜7
LargerTextにすると、1〜12
初期設定だと4

機種によっても変わらないみたいです。

設定値 title1 title2 title3 body caption1 caption2 callout footnote headline subheadline
1 25.0 19.0 17.0 14.0 11.0 11.0 13.0 12.0 14.0 12.0
2 26.0 20.0 18.0 15.0 11.0 11.0 14.0 12.0 15.0 13.0
3 27.0 21.0 19.0 16.0 11.0 11.0 15.0 12.0 16.0 14.0
4 28.0 22.0 20.0 17.0 12.0 11.0 16.0 13.0 17.0 15.0
5 30.0 24.0 22.0 19.0 14.0 13.0 18.0 15.0 19.0 17.0
6 32.0 26.0 24.0 21.0 16.0 15.0 20.0 17.0 21.0 19.0
7 34.0 28.0 26.0 23.0 18.0 17.0 22.0 19.0 23.0 21.0
8 34.0 28.0 26.0 28.0 18.0 17.0 22.0 19.0 23.0 21.0
9 34.0 28.0 26.0 33.0 18.0 17.0 22.0 19.0 23.0 21.0
10 34.0 28.0 26.0 40.0 18.0 17.0 22.0 19.0 23.0 21.0
11 34.0 28.0 26.0 47.0 18.0 17.0 22.0 19.0 23.0 21.0
12 34.0 28.0 26.0 53.0 18.0 17.0 22.0 19.0 23.0 21.0

調査方法

検証コードは以下の通りです。

import UIKit

class ViewController: UIViewController {
    let name = "4"
    override func viewDidLoad() {
        super.viewDidLoad()
        let styles: [UIFontTextStyle] = [.title1, .title2, .title3, .body, .caption1, .caption2, .callout, .footnote, .headline, .subheadline]
        let sizes = styles.map { UIFont.preferredFont(forTextStyle: $0).pointSize }
        print("|\(name)|\(sizes.map{"\($0)"}.joined(separator: "|"))|")
    }
}
17
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
17