2011-06-06 59 views
0

我試圖改變文本顏色爲我的單元格使用#像你在Android的XML例如:cell.textLabel.textColor = [UIColor #E01B4C];這樣我可以得到我想要的任何顏色。改變表格視圖使用#iphone

乾杯

+0

可能重複:http://stackoverflow.com/questions/1560081/iphone-change-hex-color-format-to-uicolor – Luke 2011-06-06 09:24:22

+0

大:)和最新你的問題? – Nitish 2011-06-06 09:26:14

+0

是的,你最好引用@Krypton發佈的鏈接並刪除這篇文章。 – EmptyStack 2011-06-06 09:26:43

回答

0

的UIColor有沒有這樣的方法來轉換十六進制顏色,你應該轉換自己:

[UIColor colorWithRed:(float)0xe0/0xff green:(float)0x1b/0xff blue:(float)0x4c/0xff alpha:1.0]; 
+0

以及我如何知道'0xe0/0xff'具有哪個十六進制值? – madcoderz 2011-06-06 10:02:14

0

我使用這個的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. 
    } 
相關問題