开发者

how to change the background colour in UITableViewStyleGrouped in iOS?

I want to change the background colour of a cell inside UITableView from default white to something else. If the style is UITableViewStylePlain then its very easy and we can just do:

tableView.backgroundColor = [UIColor blackColor];

However, the same is not happening inside UITableViewStyleG开发者_StackOverflow社区rouped.

Can anyone kindly help me out ? Thanks.


When using UITableViewStylePlain, tableView do not have a backgroundView, but when it comes to UITableViewStyleGrouped, we can see tableView's backgroundView is not nil. So the solution is simple, set this backgroundView to nil, and it's done.

tableView.backgroundColor = [UIColor blackColor];
tableView.backgroundView = nil;

And you can see the blackColor background now!


[cell setBackgroundColor:[UIColor blackcolor]];

try this and you can change cell background color.


What we can do is use an UIImageView that will span the whole of the cell. Couldn't find a better way to do this. Thanks.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜