码迷,mamicode.com
首页 > 其他好文 > 详细

UILabel 调整行间距计算frame

时间:2014-12-04 15:59:52      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:uilabel 调整行间距 计算frame

+ (UILabel *)getLabelFrame:(UILabel *)label withLineSpace:(NSInteger)lineSpace withAttributedString:(NSString *)string

{

    [label setNumberOfLines:0];

    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];

    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];

    

    [paragraphStyle setLineSpacing:lineSpace];//调整行间距

    [attributedString addAttribute:NSFontAttributeName

                       value:label.font

                       range:NSMakeRange(0, string.length)];

    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [string length])];

    label.attributedText = attributedString;

    

    CGSize size = [label.attributedText boundingRectWithSize:CGSizeMake(label.frame.size.width, 1000) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:nil].size;

    label.frame = CGRectMake(label.frame.origin.x, label.frame.origin.y, size.width, size.height);

    return label;

}


UILabel 调整行间距计算frame

标签:uilabel 调整行间距 计算frame

原文地址:http://zqlicoder1314.blog.51cto.com/3014999/1586206

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!