我想要得到UITextRange所有rects。你知道,如果UITextView换行,UITextRange将由多于1个CGRect表示。在iOS 6.0中,有一个方法是“selectionRectsForRange:”,所以你可以得到所有的CGRects。但在旧版本中,只有一个方法“firstRectForRange:” 我一遍又一遍检查的API文件,但我觉得没什么。如何从UITextRange的rects在早期的iOS版本的iOS比6.0
我的代码喜欢的打击:
UITextPosition *beginning = textView.beginningOfDocument;
UITextPosition *start = [textView positionFromPosition:beginning offset:range.location];
UITextPosition *end = [textView positionFromPosition:start offset:range.length];
UITextRange *textRange = [textView textRangeFromPosition:start toPosition:end];
//(in iOS 6.0)
NSArray *array = [textView selectionRectsForRange:textRange];
for (int i=0; i<[array count]; i++) {
NSLog(@"rect array = %@", NSStringFromCGRect([[array objectAtIndex:i] rect]));
}
// (in earlier version)
CGRect rect = [textView firstRectForRange:textRange];