Question

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!

Was it helpful?

Solution 4

I've solved with new feature

UITextField.keyboardType = UIKeyboardTypeDecimalPad;

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top