一行字显示多种颜色

 methodlab.textColor = [UIColor blackColor];

 

methodlab.attributedText =[self changeLabstrColor:5 withstr:[NSString stringWithFormat:@"使用方法:%@",_order.ctext]] ;

 

 

//改变lab中字体颜色 显示多种颜色

-(NSAttributedString*)changeLabstrColor:(int)range withstr:(NSString*)str {

    

    

   

    NSMutableAttributedString *str3 = [[NSMutableAttributedString alloc]initWithString:str];

    //设置:在0-5个单位长度内的内容显示成灰色

    [str3 addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:NSMakeRange(0, range)];

 

    return str3;

 

    

}

 

posted on 2017-01-20 16:02  小虫笔墨  阅读(202)  评论(0编辑  收藏  举报