2014-10-02 42 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