Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change UITextField keyboard type to email in Swift

In objective-c I can just say the following.

[self.promoTextField setKeyboardType:UIKeyboardTypeEmailAddress]; 

I tried googling it but just get ways to do it in objective-c.

like image 720
user1898829 Avatar asked Oct 16 '14 12:10

user1898829


People also ask

What is UITextField in swift?

An object that displays an editable text area in your interface.


2 Answers

Try this :

Swift 3

self.promoTextField.keyboardType = UIKeyboardType.emailAddress // Or Shorter version self.promoTextField.keyboardType = .emailAddress 

Swift < 3

self.promoTextField.keyboardType = UIKeyboardType.EmailAddress 
like image 66
Pintouch Avatar answered Sep 20 '22 08:09

Pintouch


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 keyboardTypes 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 } 
like image 35
Cyrille Avatar answered Sep 19 '22 08:09

Cyrille