//返回文字宽度
-(CGFloat)labWidth:(NSString *)labtext labheight:(CGFloat)labheight
{
CGFloat labWidth = 0.0f;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, labheight)];
label.numberOfLines = 0;
label.font = [UIFont systemFontOfSize:labheight];
label.text = labtext;
[label sizeToFit];
labWidth += label.bounds.size.width;
return labWidth;
}
//返回文字高度
-(CGFloat)labHeight:(NSString *)labtext labWidth:(CGFloat)labwidth textfont:(CGFloat)textfont
{
CGFloat labHeight = 0.0f;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, labwidth, 0)];
label.numberOfLines = 0;
label.font = [UIFont systemFontOfSize:textfont];
label.text = labtext;
[label sizeToFit];
labHeight += label.bounds.size.height;
return labHeight;
}
网友评论