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)
}See Also
Configuring tab content
contextMenu(menuItems:)customizationBehavior(_:for:)customizationID(_:)defaultSectionExpansion(_:)TabSectionExpansiondefaultVisibility(_:for:)disabled(_:)draggable(_:)dropDestination(for:action:)help(_:)hidden(_:)popover(isPresented:attachmentAnchor:arrowEdge:content:)popover(item:attachmentAnchor:arrowEdge:content:)sectionActions(content:)springLoadingBehavior(_:)