zoukankan      html  css  js  c++  java
  • 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;
  • 相关阅读:
    iOS-技巧性总结
    使用Xcode进行调试
    iOS-屏幕适配-UI布局
    iOS开发简单介绍
    iOS-网络处理
    iOS-数据解析XML解析的多种平台介绍
    iOS-数据持久化基础-JSON与XML数据解析
    iOS-数据持久化-第三方框架FMDB的使用
    ASP.NET的内置对象
    线性表
  • 原文地址:https://www.cnblogs.com/ly1973/p/5431903.html
Copyright © 2011-2022 走看看