Created
June 20, 2020 20:00
-
-
Save PetreVane/4bd1cd1eabab15249a76052fc206bb81 to your computer and use it in GitHub Desktop.
This is a countinuation of "Form embedded in a NavigationView" code snippet. This screen contains now 4 different Sections, each with a different component.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
@State private var pickerSelectedIndex = 0 | |
@State private var toggleOn = false | |
@State private var textFieldValue = "" | |
var treats = Treat.demoTreats | |
var body: some View { | |
// Navigation | |
NavigationView { | |
//Form to collect data | |
Form { | |
// Section with Picker presented in a different window | |
Section { | |
Picker(selection: $pickerSelectedIndex, label: Text("Treats")) { | |
ForEach(0 ..< self.treats.count) { | |
Text(self.treats[$0].name).tag($0) | |
} | |
} | |
} | |
// Section with Toggle (in the same window) | |
Section { | |
Toggle(isOn: $toggleOn) { | |
Text("Would you like to add some milk? ") | |
} | |
if toggleOn { | |
Text("Milk costs extra 0.99 Eur") | |
} | |
} | |
// Section with TextField | |
Section { | |
TextField("Insert your comments here", text: $textFieldValue) | |
} | |
// Section with Button | |
Section { | |
Button(action: { | |
print("Your order is being processed ..") | |
}) { | |
HStack(alignment: .center, spacing: 10) { | |
Image(systemName: "paperplane") | |
.foregroundColor(.green) | |
.scaledToFit() | |
Text("Confirm order") | |
.foregroundColor(.green) | |
} | |
} | |
} | |
}.navigationBarTitle(Text("Treats for your cat")) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment