Styling

Indicate how to style the text, controls, and other content contained in a view.

Topics

Setting the Border of a View

func border<S>(S, width: CGFloat) -> View

Adds a border to the view with the specified style and width.

Setting View Colors

func foregroundColor(Color?) -> View

Sets the color that the view uses for foreground elements.

func accentColor(Color?) -> View

Sets the accent color for the view and the views it contains.

Adopting View Color Schemes

func colorScheme(ColorScheme) -> View

Sets the view’s color scheme.

func preferredColorScheme(ColorScheme?) -> View

Sets the preferred color scheme for this view.

enum ColorScheme

The possible types of color schemes, like Dark Mode.

struct PreferredColorSchemeKey

A key for specifying the preferred color scheme.

Adjusting Text in a View

func keyboardType(UIKeyboardType) -> View

Sets the keyboard type for this view.

func font(Font?) -> View

Sets the default font for text in the view.

func lineLimit(Int?) -> View

Sets the maximum number of lines that text can occupy in the view.

func lineSpacing(CGFloat) -> View

Sets the amount of space between lines of text in the view.

func minimumScaleFactor(CGFloat) -> View

Sets the minimum amount that text scales down to fit the available space.

func truncationMode(Text.TruncationMode) -> View

Sets the truncation mode for lines of text that are too long to fit in the available space.

func allowsTightening(Bool) -> View

Sets whether text can compress the space between characters when necessary to fit text in a line.

func textContentType(UITextContentType?) -> View

Sets the text content type for this view, which the system uses to offer suggestions while the user enters text on an iOS or tvOS device.

func textContentType(WKTextContentType?) -> View

Sets the text content type for this view, which the system uses to offer suggestions while the user enters text on a watchOS device.

func flipsForRightToLeftLayoutDirection(Bool) -> View

Sets whether the view flips its contents horizontally when the layout direction is right-to-left.

func autocapitalization(UITextAutocapitalizationType) -> View

Sets whether to apply auto-capitalization to this view.

func disableAutocorrection(Bool?) -> View

Sets whether to disable autocorrection for this view.

Configuring Control Attributes

func labelsHidden() -> View

Hides the labels of any controls contained within this view.

func defaultWheelPickerItemHeight(CGFloat) -> View

Sets the default wheel-style picker item height.

func horizontalRadioGroupLayout() -> View

Sets the style for radio group style pickers within the view’s environment to be radio buttons horizontally arranged inside of the layout.

func controlSize(ControlSize) -> View

Sets the size class, like regular or small, for controls within this view.

enum ControlSize

The size classes, like regular or small, that you can apply to controls within a view.

Styling Specific View Types

func buttonStyle<S>(S) -> View

Sets the style for buttons within this view.

func buttonStyle<S>(S) -> View

Sets the style for buttons within this view.

func menuButtonStyle<S>(S) -> View

Sets the style for menu buttons within this view.

func pickerStyle<S>(S) -> View

Sets the style for pickers within this view.

func datePickerStyle<S>(S) -> View

Sets the style for date pickers within this view.

func textFieldStyle<S>(S) -> View

Sets the style for text fields within this view.

func toggleStyle<S>(S) -> View

Sets the style for toggles within this view.

func listStyle<S>(S) -> View

Sets the style for lists within this view.

func navigationViewStyle<S>(S) -> View

Sets the style for navigation views within this view.

View Styles

Find the built-in styles for different types of views.

Configuring a List View

func listRowInsets(EdgeInsets?) -> View

Sets the inset to be applied to the view when placed in a list.

func listRowBackground<V>(V?) -> View

Sets a view behind the view when placed in a list.

func listRowPlatterColor(Color?) -> View

Sets the color to apply to the system cell platter of the view when placed in a list.

func tag<V>(V) -> View

Sets a tag for the view in order to differentiate it from a list of view options.

Configuring Navigation and Status Bar Views

func navigationBarTitle(Text) -> View

Configures the title in the navigation bar for the view.

func navigationBarTitle(LocalizedStringKey) -> View

Configures the title of this view's navigation bar with a localized string.

func navigationBarTitle<S>(S) -> View

Configures the title of this view’s navigation bar with a string.

func navigationBarTitle(LocalizedStringKey, displayMode: NavigationBarItem.TitleDisplayMode) -> View

Configures the title of this view's navigation bar with a localized string and a display mode.

func navigationBarHidden(Bool) -> View

Hides the navigation bar for the view.

func statusBar(hidden: Bool) -> View

Sets the visibility of the status bar for the view.

Configuring Navigation and Tab Bar Item Views

func navigationBarBackButtonHidden(Bool) -> View

Hides the navigation bar back button for the view.

func navigationBarItems<L>(leading: L) -> View

Configures the navigation bar items for the view.

func navigationBarItems<L, T>(leading: L, trailing: T) -> View

Configures the navigation bar items for the view.

func navigationBarItems<T>(trailing: T) -> View

Configures the navigation bar items for the view.

struct NavigationBarItem

A configuration for a navigation bar that represents a view at the top of a navigation stack.

func tabItem<V>(() -> V) -> View

Sets the tab bar item associated with this view.

Configuring Context Menu Views

func contextMenu<MenuItems>(ContextMenu<MenuItems>?) -> View

Attaches a contextual menu and its children to the view.

struct ContextMenu

A container for views that you present as a menu items in a contextual menu in response to the standard system gesture.

Configuring Touch Bar Views

func touchBar<Content>(content: () -> Content) -> View

Sets the content that the Touch Bar displays.

func touchBar<Content>(TouchBar<Content>) -> View

Sets the touch bar and its content to be shown in the Touch Bar when applicable.

func touchBarItemPrincipal(Bool) -> View

Sets the view as having special significance to the TouchBar.

func touchBarCustomizationLabel(Text) -> View

Sets a user-visible string identifying the view’s functionality.

func touchBarItemPresence(TouchBarItemPresence) -> View

Sets the behavior of the view when being customized by the user.

struct TouchBar

A container for a view that you can show in the Touch Bar.

enum TouchBarItemPresence

Options that affect user customization of the Touch Bar.

See Also

Configuring Views

Layout

Tell a view how to arrange itself within a view hierarchy by adjusting its size, position, alignment, padding, and so on.

Accessibility

Make your views accessible to a broad range of users, including people with disabilities.

Rendering

Affect the way the system draws a view, for example by scaling or masking a view, or by applying graphical effects.