A hidden view that the accessibility system uses to generate accessibility elements.
accessibilityRepresentation(representation:)
Availability 有効性
- iOS 15.0+
- iPadOS 15.0+
- macOS 12.0+
- Mac Catalyst 15.0+
- tvOS 15.0+
- watchOS 8.0+
Technology
- Swift
UI
Declaration 宣言
Parameters パラメータ
representation
Discussion 議論
You can make controls accessible by using a custom style. For example, a custom Toggle
that you create inherits the accessibility features of Toggle
automatically. When you can’t use the parent view’s accessibility elements, use the accessibility
modifier instead. This modifier replaces default accessibility elements with different accessibility elements that you provide. You use synthetic, non-visual accessibility elements to represent what the view displays.
The example below makes a custom adjustable control accessible by explicitly defining the representation of its step increments using a Slider
:
var body: some View {
VStack {
SliderTrack(...) // Custom slider implementation.
}
.accessibilityRepresentation {
Slider(value: $value, in: 0...100) {
Text("Label")
}
}
}
SwiftUI hides the view that you provide in the representation
closure and makes it non-interactive. The framework uses it only to generate accessibility elements.