我的客戶問我如何讓數字鍵盤看起來像在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