Mojtaba
Mojtaba

Reputation: 514

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

Upvotes: 2

Views: 3895

Answers (1)

Austin
Austin

Reputation: 5655

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];

Upvotes: 13

Related Questions