Is it possible to set color to the table in a grouped table

154 views Asked by At

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?

2

There are 2 answers

1
Clarence On BEST ANSWER

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.

3
Manish Ahuja On

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;

}