NSMutableAttributedString(转)

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;

 

posted @ 2016-04-25 18:06  看谷秀  阅读(213)  评论(0编辑  收藏  举报