简体   繁体   English

使用 # iphone 更改表格视图中的文本颜色

[英]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];我正在尝试使用 # 更改我的单元格的文本颜色,就像你在 Android xml 中所做的那样: cell.textLabel.textColor = [UIColor #E01B4C]; that way i can get whatever color i desire.这样我就可以得到我想要的任何颜色。

Cheers干杯

UIColor has no such method to convert hex color, you should convert yourself: UIColor 没有这种方法来转换十六进制颜色,你应该自己转换:

[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我正在使用这个 getColor 方法并将十六进制值作为参数传递

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.
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM