How to change UITextField keyboard type to email in Swift
In Swift 3
you might use:
youremailfieldname.keyboardType = UIKeyboardType.emailAddress
Note the lowercase
in emailAddress
Note: also that you can assign the keyboard type in the
TextField
definition in the storyboard.
Try it in Swift 3:
let emailTextField: UITextField = {
let text = UITextField()
text.keyboardType = .emailAddress
return text
}()
The documentation about UITextInputTraits
, a protocol adopted by UITextField
, says it's still here:
optional var keyboardType: UIKeyboardType { get set }
And the list of all keyboardType
s is here :
enum UIKeyboardType : Int {
case Default
case ASCIICapable
case NumbersAndPunctuation
case URL
case NumberPad
case PhonePad
case NamePhonePad
case EmailAddress
case DecimalPad
case Twitter
case WebSearch
}
Try this :
Swift 3
self.promoTextField.keyboardType = UIKeyboardType.emailAddress
// Or Shorter version
self.promoTextField.keyboardType = .emailAddress
Swift < 3
self.promoTextField.keyboardType = UIKeyboardType.EmailAddress