In SwiftUI you create a TextFiled which is a standard input for each text. By default, you get a standard keyboard with all letters, numbers, and symbols.
If you need to open the keyboard with only numbers or any other mode, see this post on how to change keyboard type.
To create secure input you need to use another view called SecureFiled. It works in the same way as normal TextField but instead of text, you see * and input isn’t visible on screenshots on physical devices.
struct ContentView: View {
@State private var password: String = “”
var body: some View {
VStack {
SecureField(“Your password:”, text: $password)
TextField(“Your password:”, text: $password)
}
}
}
Result
The screenshot comes from the simulator that’s why you can see *****, in a physical device you won’t see them at all.
If you need to execute some action when the user presses the Return button from the keyboard you can do it easily.
SecureField(“Your password:”, text: $password) {
print(“Submit!”)
}