首页 > 移动平台 > 详细

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

时间:2015-08-03 17:01:31      阅读:1037      评论:0      收藏:0      [点我收藏+]

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 显示两种字体和颜色

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!