カスタマイズによりReturnボタンを設置する方法が下記サイトに掲載されている。
http://www.neoos.ch/news/46-development/54-uikeyboardtypenumberpad-and-the-missing-return-key
■ポイント
・通知センタを使う。
・Returnボタン「DONE」のimageファイルをダウンロードして使う。
通知センタ登録
- (void)viewDidLoad {
NSNotificationCenter* center;
[center addObserver:self selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:nil];
}
通知センタ削除
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:nil];
数字テンキーボードに「DONE」ボタンを追加
- (void)keyboardWillShow:(NSNotification *)note {
// create custom button
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, 163, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
[doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
// locate keyboard view
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard view found; add the custom button to it
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
[keyboard addSubview:doneButton];
}
}
UITextFieldに割り当てられた数字テンキーボードを閉じる
- (IBAction)doneButton:(id)sender {
[hogeTextField resignFirstResponder];
}
タグ:iPhone
【UIKeyboardTypeの最新記事】