https://github.com/seandev0601/100DaysOfSwiftUI
Day 27 - Project 4 - part 2 - BetterRest - 100DaysOfSwiftUI
Stepper
is a SwiftUI component used for selecting numbers with a simple -
and +
button interface.Int
, Double
, and more.in
parameter allows limiting the range of acceptable values for the stepper.step
parameter determines the increment or decrement value for each tap.formatted()
method to provide a more user-friendly display.@State private var sleepAmount = 8.0
var body: some View {
Stepper("\\(sleepAmount.formatted()) hours",
value: $sleepAmount,
in: 4...12,
step: 0.25)
}
DatePicker
for selecting dates.DatePicker
.labelsHidden**()
can be used to customize the appearance of the DatePicker.displayedComponents
parameter allows controlling the visible options in the DatePicker.struct ContentView: View {
@State private var wakeUp = Date()
var body: some View {
VStack(alignment: .trailing) {
DatePicker("Normal date", selection: $wakeUp)
DatePicker("Tap hour min", selection: $wakeUp
, displayedComponents: .hourAndMinute)
DatePicker("Tap future", selection: $wakeUp, in: Date()...)
let tomorrow = Date().addingTimeInterval(86400)
let range = Date()...tomorrow
DatePicker("Custom range", selection: $wakeUp, in: range)
DatePicker("", selection: $wakeUp)
.labelsHidden()
}
.padding(10)
.font(.title)
}
}