Text("Hello, World!")
Common Modifiers: .font(), .fontWeight(), .foregroundColor(), .lineLimit(), .multilineTextAlignment()
Image("pencil")
Image(systemName: "star.fill")
Common Modifiers: .resizable(), .aspectRatio(contentMode:), .scaledToFit(), .scaledToFill(), .clipShape()
Note: SF Symbols (App) can show you all available default images
Button("Tap Me") {
// action
}
Common Modifiers: .buttonStyle(),.padding(), .background(), .foregroundColor(), .cornerRadius(), .tint()
@State private var name = ""
TextField("Enter your name", text: $name)
Common Modifiers: .textFieldStyle(), .autocapitalization(), .disableAutocorrection(), .border()
@State private var password = ""
SecureField("Password", text: $password)
Same modifiers as TextField
@State private var enabled = false
Toggle("Enable", isOn: $enabled)
Common Modifiers: .toggleStyle(), .tint()
@State private var selection = 0
Picker("Pick", selection: $selection) {
Text("One").tag(0)
Text("Two").tag(1)
}
Common Modifiers: .pickerStyle()
@State private var value = 0
Stepper("Value: \(value)", value: $value)
@State private var sliderValue = 0.5
Slider(value: $sliderValue, in: 0...1)
VStack {
Text("Top")
Text("Bottom")
}
Initializer params: alignment, spacing
HStack {
Image(systemName: "chevron.left")
Text("Back")
}
ZStack {
Rectangle().fill(Color.blue)
Text("Overlaid")
.foregroundColor(.white)
}
HStack {
Text("Left")
Spacer()
Text("Right")
}
NavigationStack {
NavigationLink("Detail", destination: Text("Detail View"))
.navigationTitle("Main")
}
Note: NavigationView appears in older examples; prefer NavigationStack on Xcode 16+.
List(items) { item in
Text(item.name)
}
Common Modifiers: .listStyle()
ScrollView {
VStack { ForEach(0..<50) { Text("Item \($0)") } }
}
ForEach(items, id: \.id) { item in
Text(item.name)
}
ScrollView {
LazyVStack {
ForEach(1...1000, id: \.self) { Text("Row \($0)") }
}
}
Group {
Text("A")
Text("B")
}
Used to combine views for containers with view count limits.
Color.red
Used as a view to fill backgrounds or shapes.