NSDictionary *attrsDictionary = [NSDictionarydictionaryWithObject:[UIFontsystemFontOfSize:kCellContentFontSize]

                                                                forKey:NSFontAttributeName];

    NSAttributedString *attributedText = [[[NSAttributedString alloc] initWithString:_contentStr attributes:attrsDictionary] autorelease];

    NSInteger detailHeight = [BZDataDealer textViewHeightForAttributedText:attributedText

                                                                  andWidth:detailLabelWidth];

    UITextView *detailTextView = [[UITextView alloc] initWithFrame:CGRectMake(, , detailLabelWidth, detailHeight+)];  // 加3个像素

    detailTextView.scrollEnabled = NO;  // 是否允许滚动会影响高度的展示

    detailTextView.text = _contentStr;

    [containerView addSubview:detailTextView];
+ (NSInteger)textViewHeightForAttributedText:(NSAttributedString *)text andWidth:(CGFloat)width
{
UITextView *textView = [[UITextView alloc] init];
[textView setAttributedText:text];
CGSize size = [textView sizeThatFits:CGSizeMake(width, FLT_MAX)];
return (NSInteger)(size.height);
}

以前的方法用 先赋值, 再取textview的contentsize.height, iOS7后, 这个不能和了.

苹果目前很多情况下都是推荐使用 NSAttributedString 来计算一些数据.

ps: 如果

detailTextView.scrollEnabled = NO;  // 是否允许滚动会影响高度的展示

不允许滚动, 计算出的高度还是会少一点. 所以上面加了3个像素.

不知道是不是苹果你妹的bug.

 

最新文章

  1. java 判断两个list是否相等
  2. 微软的坑:Url重写竟然会引起IIS内核模式缓存不工作
  3. tomcat共享lib里面的jar包
  4. httpwebrequest 请求压缩,接受压缩的字符流请求
  5. Android之TextView的样式类Span的使用具体解释
  6. android netty5.0 编译时 java.lang.NoClassDefFoundError: io.netty.channel.nio.NioEventLoopGroup
  7. Java编程测试_类的使用
  8. tungsten-replicator安装
  9. Android 异步消息处理机制终结篇 :深入理解 Looper、Handler、Message、MessageQueue四者关系
  10. 9.1、Libgdx的输入处理的配置和查询
  11. java并发之非阻塞算法介绍
  12. 8、socket以及socketserver
  13. 精读《syntax-parser 源码》
  14. SSM面试题
  15. 通过Weeman+Ettercap配合拿下路由器管理权限
  16. scala程序开发入门
  17. 【Zookeeper系列】zookeeper面试题(转)
  18. c#读sql server数据添加到MySQL数据库
  19. 2018-2019-2 网络对抗技术 20165230 Exp6 信息搜集与漏洞扫描
  20. [HDU1890]RoboticSort

热门文章

  1. react native android 开发,基础配置笔记。
  2. DBHelper 数据库帮助类
  3. javascript 内置对象 第17节
  4. [USACO1.1.4]坏掉的项链Broken Necklace
  5. FFT —— 快速傅里叶变换
  6. MongoDB源码分析——mongo与JavaScript交互
  7. Android中View绘制流程以及invalidate()等相关方法分析(转载的文章,出处在正文已表明)
  8. Object-API-NSLog
  9. Java中ArrayList源码分析
  10. Groovy 数组操作