IOS7環境UITextView文字高度的計算

      IOS7環境中,設置UITextView.text並不能當即更新contentSize,再用textView.contentSize.height沒法獲取當前內容的高度。採用如下方法能夠解決這個問題。
spa

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        
        CGRect textFrame=[[self.textView layoutManager]usedRectForTextContainer:[self.textView textContainer]];
        height = textFrame.size.height;
        
    }else {
        
        height = self.textView.contentSize.height;
    }
相關文章
相關標籤/搜索