iOS Developer

准确计算字符串高度的方法

2017-03-30  本文已影响20人  PM_崧崧

NSMutableParagraphStyle*style = [[NSParagraphStyledefaultParagraphStyle]mutableCopy];

style.lineBreakMode=NSLineBreakByWordWrapping;

style.alignment=NSTextAlignmentLeft;

NSAttributedString*string = [[NSAttributedStringalloc]initWithString:selectNameattributes:@{NSFontAttributeName:[UIFontsystemFontOfSize:16],NSParagraphStyleAttributeName:style}];

CGSizerects =[stringboundingRectWithSize:CGSizeMake(MainScreenWidth-16,MAXFLOAT)options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeadingcontext:nil].size;

busNameLab.frame=CGRectMake(8,8,MainScreenWidth-16, rects.height+5) ;

上一篇 下一篇

猜你喜欢

热点阅读