How to change UITextField keyboard type to email in Swift

后端 未结 6 1093
伪装坚强ぢ
伪装坚强ぢ 2021-01-30 20:36

In objective-c I can just say the following.

[self.promoTextField setKeyboardType:UIKeyboardTypeEmailAddress];

I tried googling it but just ge

6条回答
  •  遇见更好的自我
    2021-01-30 21:02

    Sometimes give UITextField extension to add one method, you can use like that "textField.chooseKeyboardType(keyboardType:.pad)", perhaps this is not a good way, but useful.

    public extension UITextField {
    
    func chooseKeyboardType(_ keyboardType:UIKeyboardType) {
        switch keyboardType {
        case .emailAddress:
            self.keyboardType = .emailAddress
        case .twitter:
            self.keyboardType = .twitter
        case .numberPad:
            self.keyboardType = .numberPad
        case .numbersAndPunctuation:
            self.keyboardType = .numbersAndPunctuation
        case .asciiCapable:
            self.keyboardType = .asciiCapable
        case .URL:
            self.keyboardType = .URL
        case .decimalPad:
            self.keyboardType = .decimalPad
        case .namePhonePad:
            self.keyboardType = .namePhonePad
    
    
        default:
            self.keyboardType = .default
        }
    }
    }
    

提交回复
热议问题