Views and Controls

Present your content onscreen and handle user interactions.

Overview

Views and controls are the visual building blocks of your app’s user interface. Use them to present your app’s content onscreen. Views represent text, images, shapes, custom drawings, and compositions of any and all of these together. Controls enable user interaction with consistent APIs that adapt to their platform and context.

Combine views using containers that specify their visual relationships and hierarchy. Use methods called modifiers to customize the display, behavior, and interactivity of built-in views and those you create for your app.

You apply modifiers to views and controls to:

  • Control the size, position, and appearance attributes of the view.

  • Respond to taps, gestures, and other user interactions.

  • Support drag and drop operations.

  • Customize animations and transitions.

  • Set style preferences and other environment data.

For additional information about how to use views and controls, see Human Interface Guidelines.

Topics

Essentials

protocol View

A type that represents a SwiftUI view.

Beta
Creating and Combining Views

This tutorial guides you through building Landmarks — an iOS app for discovering and sharing the places you love. You’ll start by building the view that shows a landmark’s details.

Working with UI Controls

In the Landmarks app, users can create a profile to express their personality. To give users the ability to change their profile, you’ll add an edit mode and design the preferences screen.

Text

struct Text

A view that displays one or more lines of read-only text.

Beta
struct TextField

A control that displays an editable text interface.

Beta
struct SecureField

A control into which the user securely enters private text.

Beta
struct Font

An environment-dependent font.

Beta

Images

struct Image

A view that displays an environment-dependent image.

Beta

Buttons

struct Button

A control that performs an action when triggered.

Beta
struct NavigationLink

A button that triggers a navigation presentation when pressed.

Beta
struct PresentationLink

A button that presents content when pressed.

Deprecated
struct MenuButton

A button that displays a menu containing a list of choices when pressed.

Beta
struct EditButton

A button that toggles the edit mode for the current edit scope.

Beta
struct PasteButton

A system button that triggers reading data from the pasteboard.

Beta

Value Selectors

struct Toggle

A control that toggles between on and off states.

Beta
struct Picker

A control for selecting from a set of mutually exclusive values.

Beta
struct DatePicker

A control for selecting an absolute date.

Beta
struct Slider

A control for selecting a value from a bounded linear range of values.

Beta
struct Stepper

A control used to perform semantic increment and decrement actions.

Beta
struct SegmentedControl

A control for selecting from a set of options.

Beta

Supporting Types

struct StaticMember

A concrete wrapper for enabling implicit member expressions.

Beta
struct ViewBuilder

A custom parameter attribute that constructs views from closures.

Beta
protocol ViewModifier

A modifier that you apply to a view or another view modifier, producing a different version of the original value.

Beta
struct IdentifierValuePair

An identifier and its corresponding value.

Beta
struct IdentifierValuePairs

A collection of identifier-value pairs computed on demand.

Beta
struct NavigationButton

A button that triggers a navigation presentation when pressed.

Deprecated

See Also

User Interface

View Layout and Presentation

Combine views in stacks, generate groups and lists of views dynamically, and define view presentations and hierarchy.

Drawing and Animation

Enhance your views with colors, shapes, and shadows, and customize animated transitions between view states.

Framework Integration

Integrate SwiftUI views into existing apps, and embed AppKit, UIKit, and WatchKit views and controllers into SwiftUI view hierarchies.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software