Declaration
compose().hidden()nonisolated func hidden() -> some ViewReturn value
A hidden view.
Discussion
Hidden views are invisible and can't receive or respond to interactions. However, they do remain in the view hierarchy and affect layout. Use this modifier if you want to include a view for layout purposes, but don't want it to display.
HStack {
Image(systemName: "a.circle.fill")
Image(systemName: "b.circle.fill")
Image(systemName: "c.circle.fill")
.hidden()
Image(systemName: "d.circle.fill")
}The third circle takes up space, because it's still present, but SwiftUI doesn't draw it onscreen.
If you want to conditionally include a view in the view hierarchy, use
an if statement instead:
VStack {
HStack {
Image(systemName: "a.circle.fill")
Image(systemName: "b.circle.fill")
if !isHidden {
Image(systemName: "c.circle.fill")
}
Image(systemName: "d.circle.fill")
}
Toggle("Hide", isOn: $isHidden)
}Depending on the current value of the isHidden state variable in the
example above, controlled by the Toggle instance, SwiftUI draws
the circle or completely omits it from the layout.
See also
More in Appearance.
- backgroundSets the view's background to a style.
- badgeGenerates a badge for the view from a localized string resource.
- 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.
- 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.