Views
Published Oct 10, 2022
Contribute to Docs
In SwiftUI, Views make up an application’s user interface (UI).
View
is a protocol
that other views must conform to. Syntactically, this means that when creating new custom views, the View
protocol
must be inherited like so:
struct MyView: View {
Body of MyView
}
There are a set of requirements set by the protocol
View
that are required of all views. The body of a view is constructed using view instances.
Some built-in view instances, just referred to just as “views,” are mentioned below:
Views
- Capsule
- Creates a capsule shape that can be modified as needed.
- Circle
- Pre-built circular shape that can be visually modified as desired.
- Color
- Creates a color view, modifying the background color.
- Ellipse
- Creates an ellipse shape that can be modified as needed.
- Form
- Displays a collection of data in a single column. An example is the settings application for Apple devices.
- HStack
- The HStack view is a layout container where elements, or subviews, are arranged in a horizontal line (left-to-right).
- Image
- Allows users to incorporate images.
- Label
- Creates a component that includes an icon and a title.
- LazyHStack
- The LazyHStack view is a layout container where elements are created as needed and are arranged in a horizontal line (left-to-right).
- LazyVStack
- A view that arranges its elements in a line that grows vertically, creating items only as needed.
- List
- Presents data arranged in a column with the ability to select one or more items.
- Picker
- Allows a user to select a value from a set of exclusive values.
- Rectangle
- A rectangular shape aligned inside the frame of the view containing it.
- RoundedRectangle
- Creates a rectangular shape with rounded corners inside the frame of the view containing it.
- ScrollView
- Scrollable view within the scrollable content region.
- Spacer
- Creates space between views.
- Stepper
- Allows a user to increment and decrement a value.
- Text
- Allows users to display one or more lines of text.
- TextField
- Allows the user to insert contact information, type memos, and edit the content of a specific field.
- Toggle
- Chooses between an "on or off" state based on a Bool type value.
- VStack
- The VStack view is a layout container where elements, or subviews, are arranged in a vertical line (top-to-bottom).
- ZStack
- The ZStack view is a layout container where elements, or subviews, are arranged as overlaying one another (back-to-front).
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.