簡體   English   中英

是否可以在iPhone的鍵盤內添加完成按鈕?

[英]Is it possible to add done button inside the keyboard in iphone?

目前我正在使用iPhone應用程序,使用UITextField輸入電話號碼,用戶輸入電話號碼,然后如何隱藏鍵盤? 因為這里沒有返回按鈕,是否可以在鍵盤內添加完成按鈕,請幫幫我

提前致謝

下面提到的圖片供你參考,左邊的空白區域添加完成按鈕,有可能嗎?

是一個很好的教程。

請參閱此鏈接。 它顯示了如何在鍵盤中添加“完成”按鈕。

但我建議你改用inputAccessoryView 請參閱此SO帖子

並且必須閱讀 這個SO答案

閱讀此鏈接並嘗試在您的應用程序中編碼....

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM