iosobjective-cuitextrange

Is it possible to create UITextRange manually for first character?


Is it possible to instantiate UITextRange and for first character of UITextField? i need to access to rect of UITextField 's first character, can anyone help me?

Thanks in advance


Solution

  • You can manually create a UITextRange with the methods provided by UITextInput:

    UITextPosition *firstCharacterPosition = [textField beginningOfDocument];
    UITextPosition *secondCharacterPosition = [textField positionFromPosition:firstCharacterPosition offset:1];
    UITextRange *firstCharacterRange = [textField textRangeFromPosition:firstCharacterPosition toPosition:secondCharacterPosition];
    NSString *firstCharacter = [textField textInRange:firstCharacterRange];