4

我的客户要求我制作数字键盘的外观,就像它在 Safari 中可见一样。在 safari 中,可以看到键盘,顶部还有三个按钮,它们是 prev next 和 done。我想实现同样的目标。请告诉我实现这一目标的方法。

提前致谢

4

3 回答 3

5

这很简单,你只需要一个 UIToolBar 在你的键盘上!

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];
于 2012-04-05T08:40:08.593 回答
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

这可能有帮助..!!!

于 2012-04-05T08:44:16.150 回答
0

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

aTextField.keyboardType = UIKeyboardTypeDefault;

键盘类型可以是以下之一:

UIKeyboardTypeDefault              
UIKeyboardTypeASCIICapable         
UIKeyboardTypeNumbersAndPunctuation
UIKeyboardTypeURL                   
UIKeyboardTypeNumberPad            
UIKeyboardTypePhonePad               
UIKeyboardTypeNamePhonePad          
UIKeyboardTypeEmailAddress

你可以在这个地址找到截图:http: //gprince.yolasite.com/index/uikeyboardtype

无论如何,如果您不将键盘显示在UIWebView. 一种解决方法是在键盘顶部添加一个包含所需栏的 UIView,但您的应用可能会被拒绝。网上有很多关于这个问题的讨论。

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

于 2012-04-05T08:54:58.430 回答