首页 > 移动平台 > 详细

IOS 改变字符串中特定字符的颜色和大小。

时间:2015-02-12 11:59:58      阅读:382      评论:0      收藏:0      [点我收藏+]
 UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 300)];
    lable.text = @"其中俩字是红色,大小为17";

    NSRange rangeRmb=[lable.text rangeOfString:[NSString stringWithFormat:@"红色"]];
    NSMutableAttributedString *rmbStr=[[NSMutableAttributedString alloc] initWithString:lable.text attributes:nil];
    if ([[[UIDevice currentDevice] systemVersion] floatValue]>=6.0) {
        NSDictionary *fontDic=[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor],NSForegroundColorAttributeName,[UIFont systemFontOfSize:17],NSFontAttributeName, nil];
        [rmbStr addAttributes:fontDic range:rangeRmb];
        lable.attributedText = rmbStr;
    }else{
        lable.text=rmbStr.string;
    }

 

 

IOS 改变字符串中特定字符的颜色和大小。

原文:http://www.cnblogs.com/mlgbya/p/4287451.html

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