码迷,mamicode.com
首页 > 移动开发 > 详细

iOS一个UILabel 显示两种字体和颜色

时间:2015-08-03 17:02:41      阅读:456      评论:0      收藏:0      [点我收藏+]

标签:ios   uilabel   字体   

UILabel infoLabel3;
以空格为截断点。查找空格的位置,然后建立 NSRang。当然也可以自己指定范围。


        NSRange range;
        range = [infoLabel3.text rangeOfString:@" "];
        if (range.location != NSNotFound) {
            NSLog(@"found at location = %lu, length = %lu",(unsigned long)range.location,(unsigned long)range.length);
            
            NSInteger startIndex = range.location ;
            NSInteger endIndex = infoLabel3.text.length -1;
            range = NSMakeRange(startIndex, endIndex);
            UIFont *labelFont = [UIFont fontWithName:@"HelveticaNeue-Bold" size:15];
            NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Using NSAttributed String"];
            [str addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:range];
            [str addAttribute:NSFontAttributeName value:labelFont range: range];
            infoLabel3.attributedText = str;
        }else{
            NSLog(@"Not Found");
        }


版权声明:本文为博主原创文章,未经博主允许不得转载。

iOS一个UILabel 显示两种字体和颜色

标签:ios   uilabel   字体   

原文地址:http://blog.csdn.net/lobee/article/details/47256807

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