accessibilityLabel

Adds a label to the view that describes its contents.

Text ModifieriOS 15.0+macOS 12.0+tvOS 15.0+watchOS 8.0+accessibilityLabel(_:) in SwiftUI

Declaration

React
compose().accessibilityLabel(label: string)
Swift
nonisolated func accessibilityLabel(_ label: Text) -> Text
3 more Swift overloads share this form
Swift
@export(implementation) nonisolated func accessibilityLabel(
    _ label: LocalizedStringResource
) -> Text
Swift
nonisolated func accessibilityLabel(
    _ labelKey: LocalizedStringKey
) -> Text
Swift
nonisolated func accessibilityLabel<S>(
    _ label: S
) -> Text
where S : StringProtocol

Parameters

  • label*string

    The text view to add the label to.

Discussion

Use this method to provide an alternative accessibility label to the text that is displayed. For example, you can give an alternate label to a navigation title:

var body: some View {
    NavigationView {
        ContentView()
            .navigationTitle(Text("􀈤").accessibilityLabel("Inbox"))
    }
}

You can't style the label that you add

See also

More in Text modifiers.