禁用iphone键盘按钮

时间:2012-09-01 18:10:17

标签: ios

有没有办法禁用iPhone键盘上的“,”按钮,或至少阻止用户在我的UITextField中“?”?

2 个答案:

答案 0 :(得分:3)

是。设置文本字段的委托,然后实现以下方法:

- (BOOL)textField:(UITextField *)tf shouldChangeCharactersInRange:(NSRange)r replacementString:(NSString *)str
{
    if (tf == theTextFieldYouWannaBehaveLikeThis) {
        if ([str isEqualToString:@","]) {
            return NO;
        }
    }
    return YES;
}

答案 1 :(得分:0)

keyboardType有一个UITextField属性:

typedef enum {
    UIKeyboardTypeDefault,                // Default type for the current input method.
    UIKeyboardTypeASCIICapable,           // Displays a keyboard which can enter ASCII characters, non-ASCII keyboards remain active
    UIKeyboardTypeNumbersAndPunctuation,  // Numbers and assorted punctuation.
    UIKeyboardTypeURL,                    // A type optimized for URL entry (shows . / .com prominently).
    UIKeyboardTypeNumberPad,              // A number pad (0-9). Suitable for PIN entry.
    UIKeyboardTypePhonePad,               // A phone pad (1-9, *, 0, #, with letters under the numbers).
    UIKeyboardTypeNamePhonePad,           // A type optimized for entering a person's name or phone number.
    UIKeyboardTypeEmailAddress,           // A type optimized for multiple email address entry (shows space @ . prominently).

    UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, // Deprecated

} UIKeyboardType;