NSString *titleColor = emptyString([dataDic objectForKey:@"color"]);
if([titleColor hasPrefix:@"0X"])
{
titleColor = [titleColor substringFromIndex:2];
}
//如果是#开头的,那么截取字符串,字符串从索引为1的位置开始,一直到末尾
if ([titleColor hasPrefix:@"#"])
{
titleColor = [titleColor substringFromIndex:1];
}
// 转换成标准16进制数
// 十六进制字符串转成整形。
long colorLong = strtoul([titleColor cStringUsingEncoding:NSUTF8StringEncoding], 0, 16);
// 通过位与方法获取三色值
int R = (colorLong & 0xFF0000 )>>16;
int G = (colorLong & 0x00FF00 )>>8;
int B = colorLong & 0x0000FF;
//string转color
UIColor *wordColor = [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:1.0];
cell.titleL.textColor = wordColor;
网友评论