【问题标题】:How to hide number button on UIKeyboard?如何隐藏 UIKeyboard 上的数字按钮?
【发布时间】:2011-09-28 18:30:25
【问题描述】:

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

维护 UIKeyboard透明度??

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

谢谢。

【问题讨论】:

  • -1 ???这么愚蠢的问题?

标签: iphone uikit uikeyboard


【解决方案1】:

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];
    }
}

if([[keyboard description] hasPrefix:@"&lt;UIKeyboard"] == YES) 这一行中的前缀@"&lt;UIKeyboard" 可能不同。因此,您应该使用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 及更高版本。

【讨论】:

  • 完美,我知道……然后呢?你的答案?
【解决方案2】:

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

【讨论】:

  • 小心制作自己的键盘 - Apple 不太喜欢它,可能会拒绝您的应用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-01
  • 2012-02-07
  • 1970-01-01
  • 2022-11-01
  • 2012-07-27
相关资源
最近更新 更多