How to code a "numbers pad" like Call application
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?
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;
精彩评论