0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Automatically Adjusts Font requires using a Dynamic Type text style

Posted at
Automatically Adjusts Font requires using a Dynamic Type text style

どういう対応すると良いですか

「Automatically Adjusts Font requires using a Dynamic Type text style」というメッセージは、フォントサイズをユーザーの設定に合わせて自動調整するためには、Dynamic Typeを使用する必要があることを示しています。Dynamic Typeを使用することで、アプリは異なるデバイスやユーザーのアクセシビリティ設定に適応できます。対処方法は以下の通りです。

Dynamic Typeの利用:

UILabel、UIButton、UITextViewなどのテキストを表示するUIコンポーネントで、プロパティadjustsFontForContentSizeCategoryをtrueに設定します。これにより、ユーザーのデバイス設定に基づいてフォントサイズが自動調整されます。

テキストスタイルの指定:

Interface Builderを使用する場合、各テキスト表示コンポーネントの属性インスペクターで、フォントセクションにある「Text Style」から適切なスタイル(例:Body、Headline、Captionなど)を選択します。

コードで設定する場合は、UIFont.preferredFont(forTextStyle:)を使用して、適切なテキストスタイルを指定します。例えば、ボディテキスト用のフォントを設定するには次のようにします:

label.font = UIFont.preferredFont(forTextStyle: .body)

コンテンツサイズカテゴリの変更通知の監視:

アプリが実行中にフォントサイズが変更された場合、UIコンポーネントがそれに応じて更新されるように、UIContentSizeCategoryDidChangeNotificationの通知を監視することが必要になる場合があります。これは、特にカスタムビューを使用している場合に重要です。

以下の例は、UILabelのフォントをDynamic Typeに対応させる方法を示しています:

override func viewDidLoad() {
    super.viewDidLoad()
    
    let label = UILabel()
    label.adjustsFontForContentSizeCategory = true
    label.font = UIFont.preferredFont(forTextStyle: .body)
    view.addSubview(label)
}

この設定を行うことで、ユーザーがデバイスの設定でテキストサイズを変更しても、アプリのテキストが適切に調整されるようになります。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?