开发者

Objective C: How to make background color of UITableView Consistent

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)

Objective C: How to make background color of UITableView Consistent

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


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).


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


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"]]];

  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜