0

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!

icedwater
  • 4,701
  • 3
  • 35
  • 50
Joaquin McCoy
  • 425
  • 2
  • 7
  • 16
  • You're going to have to be more specific - where is this number going? If you don't want a UITextField, what is going to show user feedback for the numbers typed in? It would also help if you let us know what you've already tried. – Tim Dec 18 '10 at 02:09

4 Answers4

1

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];
}
Kevin Sylvestre
  • 37,288
  • 33
  • 152
  • 232
  • Yes, for something like that I add a set of subviews. But, for example, when I click "5" button, how can I set in real-time the output on the textfield? – Joaquin McCoy Dec 18 '10 at 05:52
  • Hey Joaquin. You need to use the **delegate pattern** to notify your view controller of any button presses. I've put in some code above to get you started and give you a general idea of how it can be done. – Kevin Sylvestre Dec 18 '10 at 06:02
1

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.

Di Wu
  • 6,436
  • 3
  • 35
  • 51
0

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

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
0

I've solved with new feature

UITextField.keyboardType = UIKeyboardTypeDecimalPad;
Zoe
  • 27,060
  • 21
  • 118
  • 148
Joaquin McCoy
  • 425
  • 2
  • 7
  • 16