首页 > 其他 > 详细

改变label中的某字体颜色

时间:2015-07-25 16:38:23      阅读:595      评论:0      收藏:0      [点我收藏+]

 NSString *allString=@"你家在哪里,需要我送你么";

    NSString *subString=@"在哪里";

    UILabel *stringLabel=[[UILabel alloc]init];

    stringLabel.frame=CGRectMake(0, 100, 300, 30);

    stringLabel.font=[UIFont systemFontOfSize:17];

    stringLabel.backgroundColor=[UIColor blackColor];

    stringLabel.text=allString;

    stringLabel.textColor=[UIColor whiteColor];

    [self.view addSubview:stringLabel];

    

    NSString *allS=[allString lowercaseString];

    NSString *subS=[subString lowercaseString];

    NSRange range=[allS rangeOfString:subS];

    if (range.location!=NSNotFound) {

        NSMutableAttributedString  *string=[[NSMutableAttributedString alloc]initWithString:allString];

        [string addAttribute:NSForegroundColorAttributeName value:[UIColor yellowColor] range:range];

        stringLabel.attributedText=string;

    }

 

改变label中的某字体颜色

原文:http://www.cnblogs.com/106dapeng/p/4675987.html

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