iPhone SDK NumberPad 自定义 inputView 完成按钮

发布于 2024-09-04 11:47:57 字数 243 浏览 4 评论 0原文

目前我有一个文本字段,它可以拉出数字键盘进行输入。

我想要 NumberPad 键盘布局,但我需要一个按钮来退出该响应者。

有没有办法对 UITextField 进行编码,使其具有 NumberPad 键盘,并且键盘左侧的空白空间被“完成”、“发送”或“执行”按钮替换。

或者我需要为 UITextField 创建自定义 inputView 吗?

我本以为,既然数字键盘上有一个空白键,苹果就会让它变得有用。

Currently I have a textfield, which pulls up a NumberPad keyboard for input.

I want the NumberPad keyboard layout, but I need a button to resign that responder.

Is there a way to code the UITextField so that it has a NumberPad keyboard and the space on the left of the keyboard which is blank is replaced with a 'Done', 'Send' or 'Go' button.

Or do I need to create a custom inputView for the UITextField?

I would have thought since there is a blank key on the NumberPad apple would have made it useful for something.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

吾家有女初长成 2024-09-11 11:47:57

只需尝试将带有完成按钮的 UIToolBar 作为文本字段的 inputAccessoryView 即可。在按钮单击事件中提供关闭键盘的代码。认为这应该适合你。

或者,如果您想在键盘上绘制自定义按钮,您可以在此处搜索以获取解决方案

Just try having a UIToolBar with a done button on it as the inputAccessoryView of the text field. In the button click event provide the code to dismiss the keyboard. Think that should suit you.

Or if you want to have a custom button drawn over the keyboard you can search here to get the solution

轻许诺言 2024-09-11 11:47:57

如果您使用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];
}

The empty button is needed if you use phonePad. But you can add inputAccessoryView with 'Apply' and 'Cancel' buttons, and dismiss the number pad with then.

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];
}
紅太極 2024-09-11 11:47:57

您现在需要创建一个自定义输入视图并将其分配给文本字段的输入视图属性。我目前正在研究它,但这是正确的、经过认可的方法。不过,仅仅改变一个按钮似乎有点过分了。

You need to do a custom inputview now and assign it to the inputview property of your text field. I am currently researching it, but that is the right, approved way of doing it. It seems overkill just for changing a single button though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文