我正在尝试使用#在Android xml中更改我的单元格的文本颜色,例如:cell.textLabel.textColor = [UIColor #E01B4C];
这样我可以获得我想要的任何颜色。
干杯
答案 0 :(得分:0)
UIColor没有这种转换十六进制颜色的方法,你应该转换自己:
[UIColor colorWithRed:(float)0xe0/0xff green:(float)0x1b/0xff blue:(float)0x4c/0xff alpha:1.0];
答案 1 :(得分:0)
我正在使用此getColor方法并将十六进制值作为参数传递
cell.textLabel.textColor = [self getColor:E01B4C];
然后制作这个方法。
- (UIColor *) getColor: (NSString *) hexColor//method for converting hexadecimal into colors.
{
unsigned int red, green, blue;//declaring colors of unsigned int type.
NSRange range;//range
range.length = 2;//length of range.
range.location = 0; //location of range.
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&red];//scannig red color.
range.location = 2;//location of red.
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&green];//scanning green color.
range.location = 4;//location of green.
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&blue];//scanning blue color.
return [UIColor colorWithRed:(float)(red/255.0f) green:(float)(green/255.0f) blue:(float)(blue/255.0f) alpha:1.0f];//returning customized colors.
}