开发者

how to change the background colour in UITableViewStyleGrouped in iOS?

开发者 https://www.devze.com 2023-03-11 16:41 出处:网络
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:

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

精彩评论

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

关注公众号