我试图改变文本颜色为我的单元格使用#像你在Android的XML例如:cell.textLabel.textColor = [UIColor #E01B4C];
这样我可以得到我想要的任何颜色。改变表格视图使用#iphone
干杯
我试图改变文本颜色为我的单元格使用#像你在Android的XML例如:cell.textLabel.textColor = [UIColor #E01B4C];
这样我可以得到我想要的任何颜色。改变表格视图使用#iphone
干杯
的UIColor有没有这样的方法来转换十六进制颜色,你应该转换自己:
[UIColor colorWithRed:(float)0xe0/0xff green:(float)0x1b/0xff blue:(float)0x4c/0xff alpha:1.0];
以及我如何知道'0xe0/0xff'具有哪个十六进制值? – madcoderz 2011-06-06 10:02:14
我使用这个的getColor方法,并把hexdecimal值作为参数
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.
}
可能重复:http://stackoverflow.com/questions/1560081/iphone-change-hex-color-format-to-uicolor – Luke 2011-06-06 09:24:22
大:)和最新你的问题? – Nitish 2011-06-06 09:26:14
是的,你最好引用@Krypton发布的链接并删除这篇文章。 – EmptyStack 2011-06-06 09:26:43