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

标签 ios objective-c uitextrange

是否可以实例化 UITextRangeUITextField 的第一个字符? 我需要访问 UITextField 的第一个字符的 rect,有人可以帮我吗?

提前致谢

最佳答案

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

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

关于ios - 是否可以为第一个字符手动创建 UITextRange?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22348076/

相关文章:

ios - 我如何制作一个 Sequence 来遍历从 UIView 到 View 层次结构的所有祖先( super View )到根?

ios - 无法在 Ionic 1.3.0 iOS App 中水平滚动

ios - 自定义表格 View 单元格 : IBOutlet label is nil

ios - UITextInput:selectedTextRange 与 markedTextRange?

ios - 如何从iOS 6.0之前的iOS版本中的UITextRange获取整流器

objective-c - Catexlayer 字符串大小和颜色

objective-c - 如何从ios中的uiwebview获取图像

objective-c - 保存 UIManagedDocument 时应用程序崩溃

ios - 存储单个 BOOL 全局数据值的最佳方法

ios - 控制 UITextField 中的光标位置