Contents

badge(_:)

Generates a badge for the tab from a localized string resource.

Declaration

@export(implementation) nonisolated func badge(_ resource: LocalizedStringResource) -> some TabContent<Self.TabValue>

Parameters

  • resource:

    A string resource to display as a badge.

Discussion

Use a badge to convey optional, supplementary information about a view. Keep the contents of the badge as short as possible. The string provided will appear as an indicator on the given tab.

This modifier creates a Text view on your behalf. For more information about localizing strings, see Text. The following example shows a tab that has a “New Alerts” badge when there are new alerts.

var body: some View {
    TabView {
        Tab("Home", systemImage: "house") {
            HomeView()
        }
        Tab("Alerts", systemImage: "bell") {
            AlertsView()
        }
        .badge("New Alerts")
    }
}

See Also

Configuring tab content