Programmatically change UITextField Keyboard type

前端 未结 12 1319
不知归路
不知归路 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:50

    There is a property for this called keyboardType. What you'll want to do is replace where you have strings @"Number Pad and @"Default with UIKeyboardTypeNumberPad and UIKeyboardTypeDefault.

    Your new code should look something like this:

    if(user is prompted for numeric input only)
        [textField setKeyboardType:UIKeyboardTypeNumberPad];
    
    else if(user is prompted for alphanumeric input)
        [textField setKeyboardType:UIKeyboardTypeDefault];
    

    Good Luck!

提交回复
热议问题