如何使应用程序键盘与iPhone中的safari键盘相同?

时间:2012-04-05 08:32:11

标签: iphone safari keypad

我的客户要求我制作数字键盘外观,因为它在safari中可见。在safari中,键盘是可见的,顶部有三个按钮,接下来是完成的。我想实现同样的目标。请告诉我实现这一目标的方法。

提前致谢

3 个答案:

答案 0 :(得分:5)

这很简单,你需要的只是键盘上的UIToolBar!

UIToolBar Apple Doc

而且,怎么做:

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

答案 1 :(得分:0)

UITextField有一个keyboardType属性:

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

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIToolbar_Class/Reference/Reference.html

这可能会有所帮助...... !!!

答案 2 :(得分:0)

UITextField有一个属性(keyboardType),可用于设置所需的键盘。

aTextField.keyboardType = UIKeyboardTypeDefault;

keyboardType可以是以下之一:

UIKeyboardTypeDefault              
UIKeyboardTypeASCIICapable         
UIKeyboardTypeNumbersAndPunctuation
UIKeyboardTypeURL                   
UIKeyboardTypeNumberPad            
UIKeyboardTypePhonePad               
UIKeyboardTypeNamePhonePad          
UIKeyboardTypeEmailAddress

您可以在此地址找到截图: http://gprince.yolasite.com/index/uikeyboardtype

无论如何,如果您未在UIWebView中显示键盘,则不会使用3个按钮获得顶部栏。解决方法是在键盘顶部添加包含所需条形的UIView,但您的应用可能会被拒绝。互联网上有很多关于这个问题的讨论。

我个人的解决方案是在NIB视图中添加一个UIView,并在我的键盘显示的同时显示它,而不是直接将其添加到键盘。