Contents

accessibilityLabel(_:isEnabled:)

Adds a label to the tab that describes its contents.

Declaration

nonisolated func accessibilityLabel(_ label: LocalizedStringResource, isEnabled: Bool = true) -> some TabContent<Self.TabValue>

Parameters

  • label:

    The accessibility label to apply.

  • isEnabled:

    If true the accessibility label is applied; otherwise the accessibility label is unchanged.

Discussion

Use this method to provide an accessibility label for a tab that contains content like an icon. Don’t include text in the label that repeats information that users already have. For example, don’t use the label “Library tab” because a tab already has a trait that identifies it as a tab.

var body: some View {
    TabView {
        Tab {
            FavoritesView()
        } label: {
            Image(systemName: "star.fill")
        }
        .accessibilityLabel("Favorites")
    }
}