根据文字动态计算Label高度或宽度

//根据已知的label宽度计算文字高度
CGRect rect = [reson boundingRectWithSize:CGSizeMake(label_W, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:kTextFont} context:nil];
CGFloat infoLabelH = ceilf(rect.size.height);

//根据已知的label高度计算文字宽度
CGRect rect = [reson boundingRectWithSize:CGSizeMake(0, label_H) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:kTextFont} context:nil];
CGFloat infoLabelW = ceilf(rect.size.width);
posted @ 2019-04-17 10:42  davidyff  阅读(730)  评论(0编辑  收藏  举报