mirror of
https://github.com/ivanvorobei/SwiftUI.git
synced 2026-03-12 05:21:47 +01:00
57 lines
1.6 KiB
Swift
Executable File
57 lines
1.6 KiB
Swift
Executable File
/*
|
||
See LICENSE folder for this sample’s licensing information.
|
||
|
||
Abstract:
|
||
An editable profile view.
|
||
*/
|
||
|
||
import SwiftUI
|
||
|
||
struct ProfileEditor: View {
|
||
@Binding var profile: Profile
|
||
|
||
var body: some View {
|
||
List {
|
||
HStack {
|
||
Text("Username").bold()
|
||
Divider()
|
||
TextField($profile.username)
|
||
}
|
||
|
||
Toggle(isOn: $profile.prefersNotifications) {
|
||
Text("Enable Notifications")
|
||
}
|
||
|
||
VStack(alignment: .leading, spacing: 20) {
|
||
Text("Seasonal Photo").bold()
|
||
|
||
SegmentedControl(selection: $profile.seasonalPhoto) {
|
||
ForEach(Profile.Season.allCases.identified(by: \.self)) { season in
|
||
Text(season.rawValue).tag(season)
|
||
}
|
||
}
|
||
}
|
||
.padding(.top)
|
||
|
||
VStack(alignment: .leading, spacing: 20) {
|
||
Text("Goal Date").bold()
|
||
DatePicker(
|
||
$profile.goalDate,
|
||
minimumDate: Calendar.current.date(byAdding: .year, value: -1, to: profile.goalDate),
|
||
maximumDate: Calendar.current.date(byAdding: .year, value: 1, to: profile.goalDate),
|
||
displayedComponents: .date
|
||
)
|
||
}
|
||
.padding(.top)
|
||
}
|
||
}
|
||
}
|
||
|
||
#if DEBUG
|
||
struct ProfileEditor_Previews: PreviewProvider {
|
||
static var previews: some View {
|
||
ProfileEditor(profile: .constant(.default))
|
||
}
|
||
}
|
||
#endif
|