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

NSMutableAttributedString(转)

时间:2016-04-25 19:18:11      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:

NSMutableAttributedString计算高度的问题   

        _label_page2_1 = [[UILabel alloc] init];
        _label_page2_1.numberOfLines = 0;
         
        NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:@"addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30]"];
         
        [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(8, 2)];
        [attrString addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(8, 2)];
         
        [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(13, 2)];
        [attrString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(13, 2)];
         
         
        CGRect rect = [attrString boundingRectWithSize:CGSizeMake(320, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil];
         
        _label_page2_1.frame = CGRectMake(0 ,200, ceil(rect.size.width),ceil( rect.size.height));
        _label_page2_1.backgroundColor = [UIColor yellowColor];
        _label_page2_1.attributedText = attrString;

 

NSMutableAttributedString(转)

标签:

原文地址:http://www.cnblogs.com/ly1973/p/5431903.html

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