使用通知的方式,限制UITextField的输入。
代码示例如下:
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(currentView.frame.origin.x, currentView.frame.origin.y + currentView.frame.size.height + 20.0, (self.view.frame.size.width - currentView.frame.origin.x * 2), 44)];
[self.view addSubview:textField];
textField.textColor = [UIColor blackColor];
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.3];
textField.keyboardType = UIKeyboardTypeNumberPad;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textEditChange:) name:UITextFieldTextDidChangeNotification object:textField];
- (void)textEditChange:(NSNotification *)notification
{
UITextField *textfield = notification.object;
NSString *text = textfield.text;
NSLog(@"1 text = %@, lenght &#