自适应文字高度,宽度

//自适应高度

+ (CGFloat)HeightWithText:(NSString*)text width:(CGFloat)width font:(CGFloat)font

{

CGSizesize =CGSizeMake(width,HEIGHT);

NSDictionary*dic =@{NSFontAttributeName: [UIFontsystemFontOfSize:font]};

CGRectrect = [textboundingRectWithSize:sizeoptions:NSStringDrawingUsesLineFragmentOriginattributes:diccontext:nil];

returnrect.size.height;

}

//自适应宽度

+ (CGFloat)WidthtWithText:(NSString*)text height:(CGFloat)height font:(CGFloat)font

{

CGSizesize =CGSizeMake(WIDTH, height);

NSDictionary*dic =@{NSFontAttributeName: [UIFontsystemFontOfSize:font]};

CGRectrect = [textboundingRectWithSize:sizeoptions:NSStringDrawingUsesLineFragmentOriginattributes:diccontext:nil];

returnrect.size.width;

}

你可能感兴趣的:(自适应文字高度,宽度)