ios uilabel 根据文字 计算宽度 高度

//根据宽度求高度 
 
 
 
+ (CGFloat)getLabelHeightWithText:(NSString *)text width:(CGFloat)width font: (CGFloat)font { CGRect rect = [text boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont ZKYLTFont:font]} context:nil]; return rect.size.height; }
 
 
//根据高度度求宽度
 
+ (CGFloat)getWidthWithText:(NSString *)text height:(CGFloat)height font:(CGFloat)font{ CGRect rect = [text boundingRectWithSize:CGSizeMake(MAXFLOAT, height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]} context:nil]; return rect.size.width; }
posted @ 2018-10-16 10:37  SoulDu  阅读(2999)  评论(0编辑  收藏  举报