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?
Asked
Active
Viewed 143 times
0
-
Take a look at this previous SO question http://stackoverflow.com/questions/400965/how-to-customize-the-background-border-colors-of-a-grouped-table-view – visakh7 Feb 02 '12 at 08:17
2 Answers
1
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.
-
When setting a picture as background it is like two pictures. One is like a full background, and same picture is like a frame around my grouped table and follows the scoll but the other background is fixed. The result is the frame with picture is gliding over the background with same picture and seems a little bit strange. If the frame was not there it would be perfect. Do you happen to know how to fix that? – Lars - Feb 03 '12 at 12:18
1
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;
}

Manish Ahuja
- 4,509
- 3
- 28
- 35
-
Thanks! I would appreciate if you vote up my answer and select it as accepted answer. This will help both of us in building the reputation. – Manish Ahuja Feb 02 '12 at 10:14
-
-
you can up/down vote any answer, it gives reputation points to the answerer. (you can do it by using the ^ v buttons right before the answer begins), you generaly do it as a vote of thanks. Also there is checkmark right before the answer, the one who asked the question can select any answer as selected answer by clicking on that check mark. It gives reputation points to both answerer as well as to person who asked the question. – Manish Ahuja Feb 02 '12 at 12:08