5
2

More than 3 years have passed since last update.

Accessibilityフレームワークを使う

Last updated at Posted at 2020-12-07

要約

import Accessibilityにより、accessibilityLabelの他にもアクセシビリティのコンテンツが含められるようになりました。

従来のアクセシビリティ

例えば、小説の表紙の画像があるとします。

IMG_4131.PNG

視認することができる状態であれば、画像を見てその小説がなんのタイトルであるかわかると思いますが、視認できない状態の場合もあります。そういった時、accessibilityLabelにタイトルを割り当てて、読み上げに使ったりすることを可能にします。

しかし、小説にはタイトル以外にも、著者を重要視したり、あるいは出版社だったりを知りたい場合もあるかと思います。そういった時、accessibilityLabelに全ての要素を含むと、本来タイトルだけ知れればいい人にとってはいささか読み上げが長いと感じる可能性もあります。

カスタムコンテンツの追加

iOS 14から加わったAccessibility をimportすることにより、カスタムコンテンツの追加が可能になりました。
カスタムコンテンツを含めたいクラスを、AXCustomContentProviderに適合させ、accessibilityCustomContentAXCustomContent を含めます。
AXCustomContentにはlabelvalueのセットを含めることができます。

コード

import UIKit
import Accessibility

class NovelImageView: UIImageView,AXCustomContentProvider {
    private var _accessibilityCustomContent: [AXCustomContent] = [
        AXCustomContent(label: "著者", value: "日向強"),
        AXCustomContent(label: "出版", value: "コーヒーパブリッシング"),
    ]
    var accessibilityCustomContent: [AXCustomContent]! {
        get {
            _accessibilityCustomContent
        }
        set {
            _accessibilityCustomContent = newValue
        }
    }
}

カスタムコンテンツの読み上げ

iPhoneのローターより、その他のコンテンツを選択し、上下にスワイプすることによって、accessibilityCustomContentに設定したAXCustomContentを読み上げることができます。
IMG_4132.PNG

まとめ

つかおう!アクセシビリティ!

5
2
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
5
2