title: UITextfield limit The Chinese characters length
body: <pre><code>#define MAXLENGTH 12
  - (BOOL)textField:(UITextField *) textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  
      if (textField.tag == NICKNMAE_TAG) {
          NSUInteger oldLength = [textField.text length];
          NSUInteger replacementLength = [string length];
          NSUInteger rangeLength = range.length;
  
          NSUInteger newLength = oldLength - rangeLength + replacementLength;
  
          BOOL returnKey = [string rangeOfString: @"\n"].location != NSNotFound;
  
          return newLength &lt;= MAXLENGTH || returnKey;
      }
      return YES;
  
  }
  </code></pre>
  
  <p>I used this methods to limit the length of the textfield. It worked when iputing the usual
  characters. Unfortunately, it doesn't work when inputing the Chinese characters.</p>