2012-04-05 102 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視圖,並在我的鍵盤出現的同時顯示它,而無需直接將其添加到鍵盤。