Input keyboard type - SwiftUI
In SwiftUI, you can set a keyboard type by using the keyboardType
view modifier.
The following types are defined:
asciiCapable
: a keyboard that displays standard ASCII charactersasciiCapableNumberPad
: a number pad that outputs only ASCII digitsdecimalPad
: a keyboard with numbers and a decimal pointdefault
: the default keyboardemailAddress
: a keyboard for entering email addressesnamePhonePad
: a keypad for entering a person’s name or phone numbernumberPad
: a numeric keypad for PIN entrynumbersAndPunctuation
: a keyboard for numbers and punctuationphonePad
: a keypad for entering telephone numbersURL
: a keyboard for URL entrytwitter
: a keyboard for Twitter text entry, with easy access to the at '@
' and hash '#
' characterswebSearch
: a keyboard for web search terms and URL entry
Example of using keyboardType
:
@State private var phoneNumber: String = ""
var body: some View {
TextField("Phone Number", text: $phoneNumber)
// Set keyboard type
.keyboardType(.numberPad)
}