1.使用boundingRectWithSize计算文本高度时,有时会遇到高度计算不正确问题。

常见的修改方法,可以见这个链接

https://www.jianshu.com/p/c615a76dace2

但若文本里有很多空格的话,也会影响计算效果。此时可以将空格用一个汉字或数字代替,然后误差会小很多。

NSString *descStr = [dto.introduction stringByReplacingOccurrencesOfString:@" " withString:@""];
CGSize descSize = [descStr boundingRectWithSize:CGSizeMake(kScreenWidth,MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFontsystemFontOfSize:14.f]} context:nil];
viewH += ceil(descSize.height) + 1;

 

2.解决tableview添加header后顶部空白问题,需要区分iOS11之后和之前的

if (@available(iOS 11.0, *)) {
    _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else {
    self.automaticallyAdjustsScrollViewInsets = NO;
}

 

posted on 2019-07-31 08:43  lixin327  阅读(166)  评论(0编辑  收藏  举报