gpt4 book ai didi

iphone - 如何在 iPhone OS 4 的数字键盘上显示按钮 ‘Done’?

转载 作者:行者123 更新时间:2023-12-03 18:17:24 31 4
gpt4 key购买 nike

我想向 iPhone 数字键盘添加一个“完成”按钮。左下角甚至还有一个方便的空间来放置这样的按钮。

之前,我使用了与Question 584538中描述的类似的技巧。和 Luzian Scherrer's excellent blog post ,但这在 iOS 4 中不再起作用。我可以通过创建自定义 inputView 来做到这一点,但我更喜欢扩展 Apple 的键盘而不是编写自己的键盘。

是否有新方法可以将 View 添加到标准键盘?有人为此发布了 OSS inputView 吗?还有别的办法吗?

最佳答案

您可以添加带有“应用”和“取消”按钮的 inputAccessoryView,然后关闭数字键盘。

inputAccessoryView

- (void)viewDidLoad
{
[super viewDidLoad];

UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];

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];

numberTextField.inputAccessoryView = numberToolbar;
}

-(void)cancelNumberPad{
[numberTextField resignFirstResponder];
numberTextField.text = @"";
}

-(void)doneWithNumberPad{
NSString *numberFromTheKeyboard = numberTextField.text;
[numberTextField resignFirstResponder];
}

关于iphone - 如何在 iPhone OS 4 的数字键盘上显示按钮 ‘Done’?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3014964/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com