美文网首页iOS Developer
准确计算字符串高度的方法

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

作者: PM_崧崧 | 来源:发表于2017-03-30 16:06 被阅读20次

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) ;

相关文章

网友评论

    本文标题:准确计算字符串高度的方法

    本文链接:https://www.haomeiwen.com/subject/erkpottx.html