Buttons, Sliders, Steppers and Date Pickers
Button
swift
Button("Tap me") {
print("Tapped")
}
Button {
print("Add")
} label: {
Label("Add item", systemImage: "plus")
}
Button("Delete", role: .destructive) { } // red by default
| Button style | Look |
|---|---|
.automatic | Default |
.bordered | Light tinted background |
.borderedProminent | Filled with accent color |
.borderless | Plain text |
.plain | No styling at all |
swift
Button("Continue") { }
.buttonStyle(.borderedProminent)
.controlSize(.large)
.frame(maxWidth: .infinity)
Slider and Stepper
swift
@State private var volume = 0.5
@State private var guests = 2
Slider(value: $volume, in: 0...1) {
Text("Volume")
} minimumValueLabel: {
Image(systemName: "speaker")
} maximumValueLabel: {
Image(systemName: "speaker.wave.3")
}
Text("Volume: \(Int(volume * 100))%")
Stepper("Guests: \(guests)", value: $guests, in: 1...10)
DatePicker and ColorPicker
swift
@State private var date = Date.now
@State private var color = Color.blue
DatePicker("Pick a date", selection: $date, in: Date.now..., displayedComponents: [.date, .hourAndMinute])
.datePickerStyle(.compact) // .graphical, .wheel
ColorPicker("Favorite color", selection: $color)
Text(date, format: .dateTime.day().month().year())
Menu, Link and ShareLink
swift
Menu("Options") {
Button("Copy", systemImage: "doc.on.doc") { }
Button("Share", systemImage: "square.and.arrow.up") { }
Button("Delete", systemImage: "trash", role: .destructive) { }
}
Link("Open website", destination: URL(string: "https://www.apple.com")!)
ShareLink(item: "Check out this iOS course!")
Mini Project: Booking Form
swift
struct BookingView: View {
@State private var guests = 2
@State private var date = Date.now
@State private var notes = ""
@State private var confirmed = false
var body: some View {
NavigationStack {
Form {
Stepper("Guests: \(guests)", value: $guests, in: 1...12)
DatePicker("Date", selection: $date, in: .now...)
TextField("Special requests", text: $notes, axis: .vertical)
.lineLimit(3...5)
Button("Book table") { confirmed = true }
}
.navigationTitle("Reserve")
.alert("Booked!", isPresented: $confirmed) {
Button("OK") { }
} message: {
Text("Table for \(guests) on \(date.formatted(date: .abbreviated, time: .shortened))")
}
}
}
}
Conclusion
These controls cover most input needs. Bind each to @State and pick a style that fits the screen.
Quick Summary: Button runs actions, Slider and Stepper change numbers, DatePicker picks dates and Menu groups actions.

