Programmatically change UITextField Keyboard type

前端 未结 12 1295
不知归路
不知归路 2020-11-28 19:28

Is it possible to programmatically change the keyboard type of a uitextfield so that something like this would be possible:

if(user is prompted for numeric i         


        
12条回答
  •  一整个雨季
    2020-11-28 19:42

    It's worth noting that if you want a currently-focused field to update the keyboard type immediately, there's one extra step:

    // textField is set to a UIKeyboardType other than UIKeyboardTypeEmailAddress
    
    [textField setKeyboardType:UIKeyboardTypeEmailAddress];
    [textField reloadInputViews];
    

    Without the call to reloadInputViews, the keyboard will not change until the selected field (the first responder) loses and regains focus.

    A full list of the UIKeyboardType values can be found here, or:

    typedef enum : NSInteger {
        UIKeyboardTypeDefault,
        UIKeyboardTypeASCIICapable,
        UIKeyboardTypeNumbersAndPunctuation,
        UIKeyboardTypeURL,
        UIKeyboardTypeNumberPad,
        UIKeyboardTypePhonePad,
        UIKeyboardTypeNamePhonePad,
        UIKeyboardTypeEmailAddress,
        UIKeyboardTypeDecimalPad,
        UIKeyboardTypeTwitter,
        UIKeyboardTypeWebSearch,
        UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable
    } UIKeyboardType;
    

提交回复
热议问题