Reputation: 12431
I have been trying to set the background color of my table view but am facing an issue
This is what I am trying to do.
//Set background color of table view (translucent)
self.tableView.backgroundColor = [UIColor colorWithRed:0.0 green:0.2 blue:0.5 alpha:0.7];
//Set frame for tableview
[self.tableView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-self.picker.frame.size.height)];
After setting the table cells, I saw that there is an inconsistency in the alpha level around the table view cell (see screenshot below)
Is there anyway to make the color / alpha level consistent for the background? (Note: I am not setting a background image, only color and alpha level)
Thanks!
Zhen Hoe
Upvotes: 6
Views: 23997
Reputation: 1514
All you need to do are 2 things:
E.g. A view has a table view in it.
In the XIB
file set the background of the UITableView
to clear color.
Set the background of the container view of the table view to the image you want.
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"app_background.png"]];
If the ViewController is actually a TableViewController
then set:
self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"app_background.png"]];
You can set the row background with inside the table view delegate (the view or tableview controller)
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath row] % 2 == 0) {//248 G:192 B:100
[cell setBackgroundColor: [UIColor redColor]];
} else {
[cell setBackgroundColor: [UIColor colorWithPatternImage:[UIImage imageNamed:@"xyz.png"]]];
}
}
Upvotes: 0
Reputation: 50707
You need to make the background of the UITableView clear as well as set Opaque to FALSE
[self.tableView setBackgroundColor: [UIColor clearColor]];
[self.tableView setOpaque: NO];
Upvotes: 5
Reputation: 4428
I recently ran into this problem myself and think I found the solution
self.tableView.backgroundColor = [UIColor clearColor];
self.parentViewController.view.backgroundColor = [UIColor colorWithRed:0.0 green:0.2 blue:0.5 alpha:0.7];
Give that a shot, might need some massaging for your specific case (looks like you have some picture behind that translucent blue too).
Upvotes: 22