Views

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

Button
Allows users to interact with the UI and perform certain actions.
Circle
Pre-built circular shape that can be visually modified as desired.
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.
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.
Rectangle
A rectangular shape aligned inside the frame of the view containing it.
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).

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn SwiftUI on Codecademy