1.//计算当前文字的高度
在这里千万不要使用float进行接收,否则字体会出现展示不全,距离上面和下面都有一些距离 ,float是32位的, CGFloat是64位的
- (CGFloat)getTextHeight:(NSString *)text
{
// [text boundingRectWithSize:<#(CGSize)#> options:<#(NSStringDrawingOptions)#> attributes:<#(NSDictionary *)#> context:<#(NSStringDrawingContext *)#>];
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(160, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping];
return size.height;
}
2.
CGRect rect = [str boundingRectWithSize:CGSizeMake(200, 1000) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12.0]} context:nil];