- (void)setupTextField
{
    UITextField *tf = [[UITextField alloc] init];
    
    tf.keyboardType = UIKeyboardTypeNumberPad;
    
    tf.frame = CGRectMake(80, 80, 200, 40);
    
    tf.backgroundColor = [UIColor redColor];
    
    [self.view addSubview:tf];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textfieldEditChange:) name:@"UITextFieldTextDidChangeNotification" object:tf];
}

- (void)textfieldEditChange:(NSNotification *)noti
{
    UITextField *textField = noti.object;
    
    if (textField.text.length > 11)
    {
        textField.text = [textField.text substringToIndex:11];
    }
    
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-13
  • 2022-12-23
  • 2022-12-23
  • 2021-09-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
相关资源
相似解决方案