Created
March 14, 2022 03:48
-
-
Save ashishkakkad8/fe64e4936725ddd60035cc62ed6e89aa to your computer and use it in GitHub Desktop.
How to hide Keyboard in SwiftUI?
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
private enum Field: Int, CaseIterable { | |
case username, password | |
} | |
@State private var username: String = "" | |
@State private var password: String = "" | |
@FocusState private var focusedField: Field? | |
var body: some View { | |
NavigationView { | |
Form { | |
TextField("Username", text: $username) | |
.focused($focusedField, equals: .username) | |
SecureField("Password", text: $password) | |
.focused($focusedField, equals: .password) | |
} | |
.toolbar { | |
ToolbarItem(placement: .keyboard) { | |
Button("Done") { | |
focusedField = nil | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment