我的客户问我如何让数字键盘看起来像在safari中可见。在Safari浏览器中,键盘可以看到,顶部有三个按钮,它们是prev next和done。我想达到同样的效果。请告诉我实现这一目标的方式。如何使应用程序键盘与iPhone中的safari键盘相同?
在此先感谢
我的客户问我如何让数字键盘看起来像在safari中可见。在Safari浏览器中,键盘可以看到,顶部有三个按钮,它们是prev next和done。我想达到同样的效果。请告诉我实现这一目标的方式。如何使应用程序键盘与iPhone中的safari键盘相同?
在此先感谢
这是很容易的,你需要的是在键盘的顶部UIToolBar!
而且,如何做到这一点:
UIToolbar *myToolBar = [[UIToolbar alloc] init];
myToolBar.barStyle = UIBarStyleDefault;
[myToolBar sizeToFit];
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(buttonClicked:)];
NSArray *array = [NSArray arrayWithObject:leftBarButton];
[leftBarButton release];
[myToolBar setItems:array];
myTextField.inputAccessoryView = myToolBar;
[myToolBar release];
有对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;
您的代码应阅读
if(user is prompted for numeric input only)
[textField setKeyboardType:UIKeyboardTypeNumberPad];
if(user is prompted for alphanumeric input)
[textField setKeyboardType:UIKeyboardTypeDefault];
这可能有助于.. !!!
UITextField
有一个属性(keyboardType
),可用于设置您需要的键盘。
aTextField.keyboardType = UIKeyboardTypeDefault;
键盘类型可以是下列之一:
UIKeyboardTypeDefault
UIKeyboardTypeASCIICapable
UIKeyboardTypeNumbersAndPunctuation
UIKeyboardTypeURL
UIKeyboardTypeNumberPad
UIKeyboardTypePhonePad
UIKeyboardTypeNamePhonePad
UIKeyboardTypeEmailAddress
你可以在这个网址找到截图: http://gprince.yolasite.com/index/uikeyboardtype
无论如何,你不会有3个按钮,如果拿到顶栏您不会在UIWebView
中显示您的键盘。解决方法是在您的键盘上添加一个包含所需栏的UIView,但是您的应用程序可能会被拒绝。互联网上有很多关于这个问题的讨论。
我个人的解决方案是将UIView添加到NIB视图,并在我的键盘出现的同时显示它,而无需直接将其添加到键盘。
我在代码中修正了一些拼写错误,希望你对此有所了解。 – FelixLam 2012-04-05 09:01:30
看来我错过了inputAccessoryView,感谢这个提示安东尼奥! – Beppe 2012-04-05 09:22:03