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