1

現在、入力用に NumberPad キーボードを表示するテキストフィールドがあります。

NumberPad キーボード レイアウトが必要ですが、レスポンダーを辞任するためのボタンが必要です。

UITextField に NumberPad キーボードがあり、空白のキーボードの左側のスペースが「完了」、「送信」、または「実行」ボタンに置​​き換えられるように、UITextField をコーディングする方法はありますか。

または、UITextField のカスタム inputView を作成する必要がありますか?

NumberPad アップルには空白のキーがあるので、何かに役立つと思っていたでしょう。

4

3 に答える 3

2

テキストフィールドのUIToolBarとして、完了ボタンが付いた を試してみてください。inputAccessoryViewボタン クリック イベントで、キーボードを閉じるコードを提供します。それはあなたに合うはずだと考えてください。

または、カスタム ボタンをキーボード上に描画したい場合は、ここで検索して解決策を得ることができます

于 2011-12-01T06:24:13.307 に答える
1

phonePad を使用する場合は、空のボタンが必要です。ただし、「適用」および「キャンセル」ボタンで追加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];
}
于 2012-07-08T09:44:40.993 に答える
0

ここでカスタム inputview を作成し、それをテキスト フィールドの inputview プロパティに割り当てる必要があります。私は現在それを研究していますが、それは正しい、承認された方法です。ただ、ボタンを1つ変えるだけではやり過ぎに思えます。

于 2010-07-17T15:08:17.353 に答える