[英]Is it possible to add done button inside the keyboard in iphone?
目前我正在使用iPhone應用程序,使用UITextField輸入電話號碼,用戶輸入電話號碼,然后如何隱藏鍵盤? 因為這里沒有返回按鈕,是否可以在鍵盤內添加完成按鈕,請幫幫我
提前致謝
這是一個很好的教程。
閱讀此鏈接並嘗試在您的應用程序中編碼....
http://iphone-rahulvarma.blogspot.in/2012/03/numericpad-with-done-button.html
您可以使用“應用”和“取消”按鈕添加inputAccessoryView,然后關閉數字鍵盤。
inputAccessoryView
- (void)viewDidLoad
{
[super viewDidLoad];
UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
numberToolbar.barStyle = UIBarStyleBlackTranslucent;
numberToolbar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelNumberPad)],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:@"Apply" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)],
nil];
[numberToolbar sizeToFit];
numberTextField.inputAccessoryView = numberToolbar;
}
-(void)cancelNumberPad{
[numberTextField resignFirstResponder];
numberTextField.text = @"";
}
-(void)doneWithNumberPad{
NSString *numberFromTheKeyboard = numberTextField.text;
[numberTextField resignFirstResponder];
}
如果不使用完成按鈕,您也可以通過觸摸視圖上的任何位置來隱藏數字鍵盤
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[yourtextfieldname resignFirstResponder];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.