现在的位置: 首页 > 综合 > 正文

textview的contentsize.height不能准确判断高度,尤其是在文本中同时包含中英文时,如此便不能高度自适应,求解如何textview自适应

2018年08月20日 ⁄ 综合 ⁄ 共 409字 ⁄ 字号 评论关闭

 IOS7环境中,设置UITextView.text并不能立即更新contentSize,再用textView.contentSize.height无法获取当前内容的高度。采用以下方法可以解决这个问题。

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;
    }

抱歉!评论已关闭.