2014-10-02 64 views
1

我有一個陣列充滿了UIColors。我想將它們設置爲單元格背景色,以用作餅圖上覆制顏色的關鍵點。從UIColor陣列設置單元背景

下面是這個數組:

self.sliceColors =[NSArray arrayWithObjects: 
         [UIColor colorWithRed:246/255.0 green:155/255.0 blue:0/255.0 alpha:1], 
         [UIColor colorWithRed:129/255.0 green:195/255.0 blue:29/255.0 alpha:1], 
         [UIColor colorWithRed:62/255.0 green:173/255.0 blue:219/255.0 alpha:1], 
         [UIColor colorWithRed:229/255.0 green:66/255.0 blue:115/255.0 alpha:1], 
         [UIColor colorWithRed:148/255.0 green:141/255.0 blue:139/255.0 alpha:1],nil]; 

這就是所有的罰款。我正在嘗試編寫語法來爲單元格着色。環顧四周,我發現這個:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

} 

但我不知道如何用數組中的顏色填充它。我嘗試過的所有東西都產生了語法錯誤。

+0

你想這實際上是什麼樣子?你想讓每個細胞都有這些顏色之一嗎?你想讓一個單元擁有所有的顏色嗎?你想如何顯示它們? – dfmuir 2014-10-02 18:34:16

回答

3

一個潛在的解決方案:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    cell.backgroundColor = self.sliceColors[indexPath.row % self.sliceColors.count]; 
} 
+0

作品魅力,謝謝。 – spogebob92 2014-10-02 18:53:02