2013-09-23 27 views
1

我正在使用以下代碼來確定文本視圖中可以放置多少文本而無需滾動。它適用於iOS 6,但它不適用於iOS 7.文本視圖有效(不是零),文本視圖中有文本,但開始和結束都是零。任何幫助,將不勝感激。iOS:文本視圖中可見文本的範圍

-(NSRange)visibleRangeOfTextView:(UITextView *)textView { 
    CGRect bounds = textView.bounds; 
    UITextPosition *start = [textView characterRangeAtPoint:bounds.origin].start; 
    UITextPosition *end = [textView  characterRangeAtPoint:CGPointMake(CGRectGetMaxX(bounds), CGRectGetMaxY(bounds))].end; 

    NSRange range = NSMakeRange([textView offsetFromPosition:textView.beginningOfDocument toPosition:start], 
          [textView offsetFromPosition:start toPosition:end]); 
    return range; 
} 

回答

1

設置contentInset您的TextView,

[textView setContentInset:UIEdgeInsetsMake(-45, 0, 5,0)];