开发者

How to code a "numbers pad" like Call application

开发者 https://www.devze.com 2023-01-31 08:48 出处:网络
how can I do something like this in an iPhone app?开发者_JS百科 I need to input a number but I want something like this, not a simple UITextField.

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

开发者_JS百科

How to code a "numbers pad" like Call application

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

How?

Thanks!


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.


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


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


I've solved with new feature

UITextField.keyboardType = UIKeyboardTypeDecimalPad;
0

精彩评论

暂无评论...
验证码 换一张
取 消