平常看到要設定鍵盤的型別, 如下
typedef enum : NSInteger { UIKeyboardTypeDefault, UIKeyboardTypeASCIICapable, UIKeyboardTypeNumbersAndPunctuation, UIKeyboardTypeURL, UIKeyboardTypeNumberPad, UIKeyboardTypePhonePad, UIKeyboardTypeNamePhonePad, UIKeyboardTypeEmailAddress, UIKeyboardTypeDecimalPad, UIKeyboardTypeTwitter, UIKeyboardTypeWebSearch, UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable } UIKeyboardType;
就是使用textField.keyboardType = UIKeyboardTypeNamePhonePad;
或是要把鍵盤改成選擇日期的UIDatePicker,
則是使用 textField.inputView = self.customInput;(自己宣告的UIDatePicker)
若是沒有反應, 要記得兩點:
1. reload
typedef enum : NSInteger { UIKeyboardTypeDefault, UIKeyboardTypeASCIICapable, UIKeyboardTypeNumbersAndPunctuation, UIKeyboardTypeURL, UIKeyboardTypeNumberPad, UIKeyboardTypePhonePad, UIKeyboardTypeNamePhonePad, UIKeyboardTypeEmailAddress, UIKeyboardTypeDecimalPad, UIKeyboardTypeTwitter, UIKeyboardTypeWebSearch, UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable } UIKeyboardType;
就是使用textField.keyboardType = UIKeyboardTypeNamePhonePad;
或是要把鍵盤改成選擇日期的UIDatePicker,
則是使用 textField.inputView = self.customInput;(自己宣告的UIDatePicker)
1. reload
textField.keyboardType = UIKeyboardTypeEmailAddress;
[textField reloadInputViews];
2. 必須在這個textfield被喚起時reload才有用
例如要先執行
[textField becomeFirstResponder];
或是在這個textfield的delegate被喚起的時候
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
再來進行步驟1
留言
張貼留言