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

时间:2015-02-12 11:59:58   收藏:0   阅读:386
 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;
    }

 

 

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!