是否可以手动为第一个字符创建UITextRange?

Moj*_*aba 1 objective-c ios uitextrange

是否有可能实例化UITextRange并为第一个字符UITextField?我需要访问rect的UITextField第一个角色,任何人都可以帮助我吗?

提前致谢

Aus*_*tin 11

您可以UITextRange使用以下方法提供的方法手动创建UITextInput:

UITextPosition *firstCharacterPosition = [textField beginningOfDocument];
UITextPosition *secondCharacterPosition = [textField positionFromPosition:firstCharacterPosition offset:1];
UITextRange *firstCharacterRange = [textField textRangeFromPosition:firstCharacterPosition toPosition:secondCharacterPosition];
NSString *firstCharacter = [textField textInRange:firstCharacterRange];
Run Code Online (Sandbox Code Playgroud)