2012-04-05 46 views

回答

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

我在代码中修正了一些拼写错误,希望你对此有所了解。 – FelixLam 2012-04-05 09:01:30

+1

看来我错过了inputAccessoryView,感谢这个提示安东尼奥! – Beppe 2012-04-05 09:22:03

0

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

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

这可能有助于.. !!!

0

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

aTextField.keyboardType = UIKeyboardTypeDefault; 

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

UIKeyboardTypeDefault    
UIKeyboardTypeASCIICapable   
UIKeyboardTypeNumbersAndPunctuation 
UIKeyboardTypeURL     
UIKeyboardTypeNumberPad    
UIKeyboardTypePhonePad    
UIKeyboardTypeNamePhonePad   
UIKeyboardTypeEmailAddress 

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

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

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