UIText Field



  • A small gap should be made between the letters of entry using UITextFiled. I use Text, it's working, but when I have to rewrite the text, say correct the letter in the middle, the letter is added at the end of the word, not the place where I pointed out.

    Code:

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
    {
        [self updateTypedText:string andTextField:textField range:range];
        return YES;
    }
    
    • (void)updateTypedText:(NSString*) string andTextField:(UITextField*)textField range:(NSRange)range
      {
      if (textField == _emailTextField) {
      NSString *newString = textField.text;
      NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString: newString];
      [attributedString addAttribute:NSKernAttributeName
      value:@(2)
      range:NSMakeRange(0, newString.length)];

        textField.attributedText = attributedString;
      

      }

    }

    How do you fix that?



  • If you want to add the letter, use this method. NSMutableString insertString:atIndex:

    If you want to replace, method NSMutableString replaceCharactersInRange:withString: or NSMutableString replaceOccurrencesOfString:withString:options:range:(last method to substitute the entry of the sub-structure)




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2