I know how to set color to a plain table. If shifting to a grouped table the background color will also shift and be in the background outside the table itself. Is it possible to set color to the table also. I.e. one color for the outside area and another for the table?

有帮助吗?

解决方案

This can be done by adding a few lines of code.

For using image as background,

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

For using single color you can use,

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

For more detail, You can look up this tutorial.

其他提示

For outer color you can set Table background color via interface builder or through code using

[myTableView setBackgroundColor: [UIColor redColor]];

and for Inner color, you can set the background color of the cell in UITableView datasource method:

 -(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;

}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top