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 of the text displayed by this view.

func accentColor(Color?) -> View

Sets the accent color for this 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 presentation.

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 this view.

func lineLimit(Int?) -> View

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

func lineSpacing(CGFloat) -> View

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

func multilineTextAlignment(TextAlignment) -> View

Sets the alignment of multiline text in this view.

func minimumScaleFactor(CGFloat) -> View

Sets the minimum amount that text in this view scales down to fit in 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 in this view 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 this 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 this view to be horizontally positioned with the radio buttons inside the layout.

func controlSize(ControlSize) -> View

Sets the size 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 to a button style with a custom appearance and custom interaction behavior.

func buttonStyle<S>(S) -> View

Sets the style for buttons within this view to a button style with a custom appearance and standard interaction behavior.

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

Applies an inset to the rows in a list.

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

Places a custom background view behind a list row item.

func listRowPlatterColor(Color?) -> View

Sets the color that the system applies to the row background when this view is placed in a list.

func tag<V>(V) -> View

Sets the unique tag value of this view.

Configuring Navigation and Status Bar Views

func navigationBarTitle(Text) -> View

Sets the title in the navigation bar for this view.

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

Sets the title and display mode in the navigation bar for this view.

func navigationBarTitle(LocalizedStringKey) -> View

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

func navigationBarTitle<S>(S) -> View

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

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

Sets the title and display mode in the navigation bar for this view.

func navigationBarHidden(Bool) -> View

Hides the navigation bar for the view.

func statusBar(hidden: Bool) -> View

Sets the visibility of the status bar.

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 this 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 context menu and its children to the view.

struct ContextMenu

A container for views that you present as menu items in a contextual menu after completion of 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 content to be shown in the Touch Bar when applicable.

func touchBarItemPrincipal(Bool) -> View

Set principal views that have special significance to this Touch Bar.

func touchBarCustomizationLabel(Text) -> View

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

func touchBarItemPresence(TouchBarItemPresence) -> View

Sets the behavior of the user-customized view.

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.