1
1

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.

【SwiftUI】アクセシビリティで「文字を太くする」がオンになっているか判定する

Last updated at Posted at 2023-05-23

はじめに

アクセシビリティ設定によってアプリのUIは結構変化します。

アクセシビリティを頭に入れて開発して、アクセシビリティによるUIの変化に対応できるようになりましょう!

今回は文字の太さの設定です。

「文字を太くする」の場所

アクセシビリティ → 画面表示とテキストサイズ → 文字を太くする

Simulator Screenshot - iPhone 14 Pro - 2023-05-23 at 22.10.57.png Simulator Screenshot - iPhone 14 Pro - 2023-05-23 at 22.11.04.png

実装

import SwiftUI

struct ContentView: View {
    @Environment(\.legibilityWeight) var legibilityWeight
    var body: some View {
        switch legibilityWeight {
        case .regular:
            Text("regular")
        case .bold:
            Text("bold")
        case .none:
            Text("none")
        case .some(_):
            Text("some")
        }
    }
}
regular bold
Simulator Screenshot - iPhone 14 Pro - 2023-05-23 at 22.12.29.png Simulator Screenshot - iPhone 14 Pro - 2023-05-23 at 22.12.41.png

文字の太さを固定したい

import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("regular")
            .environment(\.legibilityWeight, .regular)
    }
}

おわり

これまでにアクセシビリティ系の記事は結構書いてきました。
アクセシビリティマスターになりたいですね

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?