`
johnie_sheng
  • 浏览: 110493 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

iOS的UILable一行显示多样字符

阅读更多

要现实AABBBBB的效果:

 

        NSString *aString = @"AABBBBB";
        NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc]
                                                  initWithString:aString];
        //把AA的字体颜色变为红色
        [attriString addAttributes:@{NSForegroundColorAttributeName:
                                         [UIColor redColor],
                                     NSFontAttributeName:
                                         [UIFont boldSystemFontOfSize:14]}
                             range:NSMakeRange(0, 2)];
        
        [attriString addAttributes:@{NSForegroundColorAttributeName:
                                         [UIColor blackColor],
                                     NSFontAttributeName:
                                         [UIFont boldSystemFontOfSize:18]}
                             range:NSMakeRange(2, aString.length - 2)];
        
        //显示文本
        [aLable setAttributedText:attriString];

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics