如何隐藏UIKeyboard上的数字按钮?

时间:2011-09-28 18:30:26

标签: iphone uikit uikeyboard

有没有办法隐藏数字按钮空格按钮

enter image description here

Mantaining UIKeyboard 透明度 ??

我需要一个只有字母,退格和NEXT按钮的键盘,没有别的 我需要iOS 3.1 +的兼容性!

感谢。

2 个答案:

答案 0 :(得分:0)

除了制作自己的键盘(并不困难)外,还可以使用UITextField和委托方法来过滤输入。

答案 1 :(得分:0)

This page has a great tutorial about customizing a keyboard。看起来您可以使用它来隐藏您不想要的按钮,或者更改当前按钮。

基本上,您应该注册为UIKeyboardWillShowNotification

的观察者
[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(keyboardWillShow:) 
                                             name:UIKeyboardWillShowNotification 
                                           object:nil];

并在keyboardWillShow:通知处理程序中进行自定义:

- (void)keyboardWillShow:(NSNotification *)notification { 
    // locate keyboard view
    UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
    UIView* keyboard;
    for(int i=0; i<[tempWindow.subviews count]; i++) {
        keyboard = [tempWindow.subviews objectAtIndex:i];
        // keyboard view found; add the customization to it
        if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
            UIView *customView = [[UIView alloc] init];
            // do stuff to customView here
            [keyboard addSubview:customView];
    }
}

此行@"<UIKeyboard"中的前缀if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)可能不同。因此,您应该使用NSLog循环一次以打印出所有子视图说明,以查看您需要检查的字符串。


以下是有关提供的默认键盘(非自定义)的一些信息

UIKeyboardType - The type of keyboard to display for a given text-based view.

查看this UIKeyboardType page以获取每种键盘类型的图像。

以下是UITextInputTraits Protocol Reference

的一些定义
typedef enum {
   UIKeyboardTypeDefault,
   UIKeyboardTypeASCIICapable,
   UIKeyboardTypeNumbersAndPunctuation,
   UIKeyboardTypeURL,
   UIKeyboardTypeNumberPad,
   UIKeyboardTypePhonePad,
   UIKeyboardTypeNamePhonePad,
   UIKeyboardTypeEmailAddress,
   UIKeyboardTypeDecimalPad,
   UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable
} UIKeyboardType;
  
      
  • UIKeyboardTypeDefault
  •   
     

使用默认键盘作为当前输入法。可用   iOS 2.0及更高版本。

     
      
  • UIKeyboardTypeASCIICapable
  •   
     

使用显示标准ASCII字符的键盘。可用   iOS 2.0及更高版本。

     
      
  • UIKeyboardTypeNumbersAndPunctuation
  •   
     

使用数字和标点符号键盘。适用于iOS 2.0和   后面。

     
      
  • UIKeyboardTypeURL
  •   
     

使用针对URL输入优化的键盘。此类型的特色是“。”,“/”,   和“.com”突出。适用于iOS 2.0及更高版本。

     
      
  • UIKeyboardTypeNumberPad
  •   
     

使用专为PIN输入设计的数字小键盘。这种类型的特点   数字0到9突出显示。此键盘类型不支持   自动大写。适用于iOS 2.0及更高版本。

     
      
  • UIKeyboardTypePhonePad
  •   
     

使用专为输入电话号码而设计的键盘。这个类型   具有数字0到9以及“*”和“#”字符   显着。此键盘类型不支持自动大写。   适用于iOS 2.0及更高版本。

     
      
  • UIKeyboardTypeNamePhonePad
  •   
     

使用专为输入人名或电话号码而设计的键盘。   此键盘类型不支持自动大写。可用   iOS 2.0及更高版本。

     
      
  • UIKeyboardTypeEmailAddress
  •   
     

使用优化的键盘指定电子邮件地址。这个类型   突出显示“@”,“。”和空格字符。可用   iOS 2.0及更高版本。

     
      
  • UIKeyboardTypeDecimalPad
  •   
     

使用带数字和小数点的键盘。适用于iOS 4.1   以后。

     
      
  • UIKeyboardTypeAlphabet
  •   
     

已过时。请改用UIKeyboardTypeASCIICapable。适用于iOS   2.0及更高版本。