我想要得到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];