//计算文本高度
+ (CGFloat)calculateStringHeight:(NSString *)string {
CGFloat height = 0;
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
NSDictionary * attributes = @{
NSFontAttributeName:[FFStyle fontPingFangWithSize:14],
NSParagraphStyleAttributeName: paragraphStyle
};
CGSize textRect = CGSizeMake(FF_SCREEN_WIDTH - 24, MAXFLOAT);
CGFloat textHeight = [string boundingRectWithSize: textRect
options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading
attributes:attributes
context:nil].size.height;
height = ceil(textHeight);
return height;
}
网友评论