Contents

View styles

Apply built-in and custom appearances and behaviors to different types of views.

Overview

SwiftUI defines built-in styles for certain kinds of views and automatically selects the appropriate style for a particular presentation context. For example, a Label might appear as an icon, a string title, or both, depending on factors like the platform, whether the view appears in a toolbar, and so on.

[Image]

You can override the automatic style by using one of the style view modifiers. These modifiers typically propagate throughout a container view, so that you can wrap a view hierarchy in a style modifier to affect all the views of the given type within the hierarchy.

Any of the style protocols that define a makeBody(configuration:) method, like ToggleStyle, also enable you to define custom styles. Create a type that conforms to the corresponding style protocol and implement its makeBody(configuration:) method. Then apply the new style using a style view modifier exactly like a built-in style.

Topics

Styling views with Liquid Glass

Styling buttons

Styling pickers

Styling menus

Styling toggles

Styling indicators

Styling views that display text

Styling collection views

Styling navigation views

Styling groups

Styling windows from a view inside the window

Adding a glass background on views in visionOS

See Also

Views