// // UILabel+Size.m // shiku_im // // Created by JayLuo on 2020/4/29. // Copyright © 2020 Reese. All rights reserved. // #import "UILabel+Size.h" @implementation UILabel (Size) + (CGFloat)getHeightByWidth:(CGFloat)width title:(NSString *)title font:(UIFont *)font { UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 0)]; label.text = title; label.font = font; label.numberOfLines = 0; [label sizeToFit]; CGFloat height = label.frame.size.height; return ceil(height); } + (CGFloat)getWidthWithTitle:(NSString *)title font:(UIFont *)font { UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 1000, 0)]; label.text = title; label.font = font; [label sizeToFit]; CGFloat width = label.frame.size.width; return ceil(width); } @end