クライアントから、サファリで表示されるテンキーの外観を作成するように依頼されました。サファリでは、キーパッドが表示され、上部にさらに3つのボタンがあり、それらは次に実行されます。同じことを実現したいです。これを実現する方法を教えてください。
前もって感謝します
それはとても簡単です。必要なのは、キーボードの上にある 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 の 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];
これは役立つかもしれません.. !!!
UITextField
keyboardType
には、必要なキーボードを設定するのに役立つプロパティ ( ) があります。
aTextField.keyboardType = UIKeyboardTypeDefault;
keyboardType は、次のいずれかになります。
UIKeyboardTypeDefault
UIKeyboardTypeASCIICapable
UIKeyboardTypeNumbersAndPunctuation
UIKeyboardTypeURL
UIKeyboardTypeNumberPad
UIKeyboardTypePhonePad
UIKeyboardTypeNamePhonePad
UIKeyboardTypeEmailAddress
このアドレスでスクリーンショットを見つけることができます: http://gprince.yolasite.com/index/uikeyboardtype
とにかく、 でキーボードを表示しないと、3 つのボタンがあるトップ バーが表示されませんUIWebView
。回避策は、必要なバーを含む UIView をキーボードの上に追加することですが、アプリが拒否される可能性があります。この問題については、インターネット上で多くの議論が行われています。
私の個人的な解決策は、UIView を NIB ビューに追加し、キーボードに直接追加せずに、キーボードが表示されると同時にそれを表示することです。