Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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;

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top