View ModifieriOS 16.0+macOS 13.0+
Overloads
2 ways to call compose().badge(). Each is one SwiftUI overload, picked by the arguments you pass.
compose().badge(resource: string | null)@export(implementation) nonisolated func badge(
_ resource: LocalizedStringResource?
) -> some View3 more Swift overloads share this form
nonisolated func badge(_ key: LocalizedStringKey?) -> some Viewnonisolated func badge(_ label: Text?) -> some Viewnonisolated func badge<S>(
_ label: S?
) -> some View
where S : StringProtocolParameters
resource*string | nullAn optional string resource to display as a badge. Set the value to
nilto hide the badge.
Discussion
Use a badge to convey optional, supplementary information about a view. Keep the contents of the badge as short as possible. Badges appear in list rows, tab bars, toolbar items, and menus.
This modifier creates a Text view on your behalf. For
more information about localizing strings, see Text. The following
example shows a list with a "Default" badge on one of its rows.
NavigationView {
List(servers) { server in
Text(server.name)
.badge(server.isDefault ? "Default" : nil)
}
.navigationTitle("Servers")
}See also
More in Appearance.
- backgroundSets the view's background to a style.
- badgeProminenceSpecifies the prominence of badges created by this view.
- borderAdds a border to this view with the specified style and width.
- buttonSizingThe preferred sizing behavior of buttons in the view hierarchy.
- containerBackgroundSets the container background of the enclosing container using a view.
- headerProminenceSets the header prominence for this view.
- hiddenHides this view unconditionally.
- imageScaleScales images within the view according to one of the relative sizes available including small, medium, and large images sizes.
- labelIconToTitleSpacingSet the spacing between the icon and title in labels.
- labelReservedIconWidthSet the width reserved for icons in labels.
- labelsHiddenHides the labels of any controls contained within this view.
- labelsVisibilityControls the visibility of labels of any controls contained within this view.