change text color in table view using # iphone
i'm trying to change the text color for my cells using the # like you do in Android xml for example: cell.textLabel.textColor = [UIColor #E01B4C];
that way i can get whatever colo开发者_如何学JAVAr i desire.
Cheers
UIColor has no such method to convert hex color, you should convert yourself:
[UIColor colorWithRed:(float)0xe0/0xff green:(float)0x1b/0xff blue:(float)0x4c/0xff alpha:1.0];
I am using this getColor method and passing hexdecimal value as an argument
cell.textLabel.textColor = [self getColor:E01B4C];
then make this method.
- (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.
}
精彩评论