struct ContentView: View {
@State var username: String = ""
var body: some View {
VStack(alignment: .leading) {
TextField("Enter username...", text: $username)
Text("Your username: \(username)")
}.padding()
}
}
OnEditChanged
VStack(alignment: .leading) {
TextField("Enter username...", text: $username, onEditingChanged: { (changed) in
print("Username onEditingChanged - \(changed)")
}) {
print("Username onCommit")
}
Text("Your username: \(username)")
}.padding()
Border Style
TextField("Enter username...", text: $username)
.textFieldStyle(RoundedBorderTextFieldStyle())
Text Above TextField
VStack(alignment: .leading) {
Text("Username")
.font(.callout)
.bold()
TextField("Enter username...", text: $username)
.textFieldStyle(RoundedBorderTextFieldStyle())
}.padding()
Background Color
TextField("Enter username...", text: $username)
.background(Color.blue)
References:
https://www.simpleswiftguide.com/swiftui-textfield-complete-tutorial/
No comments:
Post a Comment