キーボードタイプを指定する方法のメモです。
(iOS5 で試しています。)
UITextFieldのプロパティにkeybordTypeを指定すると、
表示されるキーボードを変更することが可能です。
iOS5では、次のタイプが用意されています。
typedef enum {
UIKeyboardTypeDefault,
UIKeyboardTypeASCIICapable,
UIKeyboardTypeNumbersAndPunctuation,
UIKeyboardTypeURL,
UIKeyboardTypeNumberPad,
UIKeyboardTypePhonePad,
UIKeyboardTypeNamePhonePad,
UIKeyboardTypeEmailAddress,
UIKeyboardTypeDecimalPad,
UIKeyboardTypeTwitter,
UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable
} UIKeyboardType;
試しに、
数字入力用キーボードを設定するサンプルを書いてみます。
こんな感じになります。
@implementation ViewController
– (void)viewDidLoad
{
[super viewDidLoad];
// テキストフィールドの用意
UITextField *textfield = [[UITextField alloc] initWithFrame:CGRectMake(50, 50, 200, 40)];
textfield.borderStyle = UITextBorderStyleRoundedRect;
// キーボードタイプを指定
textfield.keyboardType = UIKeyboardTypeNumberPad;
[self.view addSubview:textfield];
}
@end