自定义lable指定范围的字体颜色

NSString *str1 = @"1111";

NSString *str2 = @"2222";

[self customizeStr:str1 colorStr:str2];

}

 

- (void)customizeStr:(NSString *)str colorStr:(NSString *)colorStr

{

NSString *apendStr = [NSString stringWithFormat:@"%@%@",str,colorStr];

NSMutableAttributedString *customizeStr = [[NSMutableAttributedStringalloc]initWithString:apendStr];

NSDictionary *atr = @{NSFontAttributeName:[UIFontboldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColorgreenColor]};

NSRange colorStrRan = NSMakeRange(2, 4);

[customizeStr setAttributes:atr range:colorStrRan];

_colorLabel.attributedText = customizeStr;

}

 
posted @ 2015-07-23 09:31  江南花印孓  阅读(140)  评论(0编辑  收藏  举报