accessibilityActions

Adds multiple accessibility actions to the view.

View ModifieriOS 16.0+macOS 13.0+tvOS 16.0+watchOS 9.0+

Overloads

2 ways to call compose().accessibilityActions(). Each is one SwiftUI overload, picked by the arguments you pass.

React
compose().accessibilityActions(content: ReactNode)
Swift
nonisolated func accessibilityActions<Content>(
    @ContentBuilder _ content: () -> Content
) -> some View
where Content : View

Parameters

  • content*ReactNode

Discussion

Actions allow assistive technologies, such as the VoiceOver, to interact with the view by invoking the action. For example, this is how a dynamic number of custom action could be added to a view.

var isDraft: Bool

var body: some View {
    ContentView()
        .accessibilityActions {
            ForEach(actions) { action in
                Button {
                    action()
                } label: {
                    Text(action.title)
                }
            }

            if isDraft {
                Button {
                    // Handle Delete
                } label: {
                    Text("Delete")
                }
            }
        }

See also

More in Accessibility.