2012-02-02 45 views
0

设置颜色表中我知道如何设置颜色为纯表。 如果切换到组合表格,背景颜色也会移动并位于表格本身之外的背景中。 也可以设置颜色到表格。即一种颜色用于外部区域,另一种用于桌面?是否有可能在分组表

+0

看看这个以前SO质疑http://stackoverflow.com/questions/400965/how-to-customize-the-background-border-colors-of-a-grouped-table-view – visakh7 2012-02-02 08:17:56

回答

1

这可以通过添加几行代码来完成。

对于使用图像作为背景,

tableView.opaque = NO; 
[tableView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"image.png"]]]; 

对于使用单一颜色,您可以使用,

tableView.opaque = NO; 
    [tableView setBackgroundColor:[UIColor blueColor]]; 

更多详细信息,你可以看一下this tutorial

+0

真是太爽了,谢谢。 – 2012-02-02 09:35:38

+0

将图片设置为背景时,就像两张图片。一个就像一个完整的背景,相同的图像就像我的分组桌子周围的框架,跟随着scoll,但另一个背景是固定的。结果是带有图片的框架在相同的图片背景下滑动,看起来有点奇怪。如果框架不在那里,那将是完美的。你碰巧知道如何解决这个问题? – 2012-02-03 12:18:23

1

对于使用

[myTableView setBackgroundColor: [UIColor redColor]]; 

和内彩,可以设置将电池在UITableView的数据源的方法的背景颜色外的颜色可以通过界面生成器或通过代码设置表背景色:

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString * CellIdentifier = @"customCell"; 
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
} 

cell.backgroundColor = [UIColor greenColor]; 

return cell; 

} 
+0

谢谢,效果很好! – 2012-02-02 09:35:14

+0

谢谢!如果您投票回答我的答案并将其选为接受答案,我将不胜感激。这将有助于我们建立声誉。 – 2012-02-02 10:14:06

+0

现在我将你的答案标记为一个有用的答案。你是这个意思吗?? – 2012-02-02 11:48:51