badge(_:)
Generates a badge for a tab from an integer value.
Declaration
nonisolated func badge(_ count: Int) -> some TabContent<Self.TabValue>
Parameters
- count:
An integer value to display in the badge. Set the value to zero to hide the badge.
Discussion
Use a badge to convey optional, supplementary information about a view. The number provided will appear as a numerical indicator on the given tab.
The following example shows a TabView with the value of alerts.count displayed as a badge on the alerts tab.
TabView {
Tab("Home", systemImage: "house") {
HomeView()
}
Tab("Alerts", systemImage: "bell") {
AlertsView()
}
.badge(alerts.count)
}