如何编写“数字键盘”代码喜欢呼叫应用程序

发布于 2024-10-08 16:33:11 字数 182 浏览 1 评论 0原文

我怎样才能在iPhone应用程序中做这样的事情?

iphone app snapshot

我需要输入一个数字,但我想要这样的东西,而不是简单的 UITextField。

如何?

谢谢!

how can I do something like this in an iPhone app?

iphone app screenshot

I need to input a number but I want something like this, not a simple UITextField.

How?

Thanks!

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

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

发布评论

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

评论(4

往事风中埋 2024-10-15 16:33:11

我同意凯文的观点。但如果你决定实现自己的类似键盘的键盘,你可能不得不失去原始 iOS 键盘提供的所有这些好功能。

I Agree with Kevin. But if you decide to implement your own keyboard-like pad you may have to lose all those nice features provided by the original iOS keyboard.

行至春深 2024-10-15 16:33:11

如果您希望它看起来像您发送的内容,则必须创建一个自定义 UIView。基本上为每个控件添加一组子视图(UIButtons)。然后为自定义 UIView 创建一个委托,用于通知值更改。例如,这里有一些可以帮助您入门的粗略代码:

// CustomNumbersView.m

- (void)button1DidClick:(id)sender
{
  [self.delegate customNumbersView:self didSelectKeyWithValue:@"1"];
}

- (void)button2DidClick:(id)sender
{
  [self.delegate customNumbersView:self didSelectKeyWithValue:@"2"];
}

// MainViewController.m

- (void)viewDidLoad
{
  [super viewDidLoad];
  CustomNumbersView *customNubmersView = [[CustomNumbersView alloc] initWithFrame:...];
  customNumbersView.delegate = self;
}

- (void)customNumbersView:(CustomNumbersView *)customNumbersView didSelectKeyWithValue:(NSString *)value
{
  self.mainTextField.text = [NSString stringWithFormat:@"%@%@", self.mainTextField.text, value];
}

You will have to create a custom UIView if you want it to look like what you sent. Basically add a set of subviews (UIButtons) for each control. Then create a delegate for the custom UIView that will notify of value changes. For example, here is some rough code to get you started:

// CustomNumbersView.m

- (void)button1DidClick:(id)sender
{
  [self.delegate customNumbersView:self didSelectKeyWithValue:@"1"];
}

- (void)button2DidClick:(id)sender
{
  [self.delegate customNumbersView:self didSelectKeyWithValue:@"2"];
}

// MainViewController.m

- (void)viewDidLoad
{
  [super viewDidLoad];
  CustomNumbersView *customNubmersView = [[CustomNumbersView alloc] initWithFrame:...];
  customNumbersView.delegate = self;
}

- (void)customNumbersView:(CustomNumbersView *)customNumbersView didSelectKeyWithValue:(NSString *)value
{
  self.mainTextField.text = [NSString stringWithFormat:@"%@%@", self.mainTextField.text, value];
}
Smile简单爱 2024-10-15 16:33:11

由于我的程序中的多种情况都需要一个键盘,因此我编写了一个委托驱动的键盘

As I need one in several situations in my programs, I wrote a delegate-driven KeyPad.

尝蛊 2024-10-15 16:33:11

我已经用新功能解决了

UITextField.keyboardType = UIKeyboardTypeDecimalPad;

I've solved with new feature

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