简体   繁体   English

如何设置分组UITableView的背景颜色?

[英]How do I set the background color of a grouped UITableView?

I want conjoined email & password textfields like so - 我想要联合电子邮件和密码文本字段,如此 -

在此输入图像描述

See how both the fields are nicely rounded & the background color is blue. 看看这两个字段是如何圆润的,背景颜色是蓝色。

The way I have implemented this is to create a custom tableViewCell with a label and a text field in a grouped table view probably with a single section and two rows one of which is for username and other for password. 我实现这个的方法是在分组表视图中创建一个带有标签和文本字段的自定义tableViewCell,可能只有一个部分和两行,其中一行用于用户名,另一行用于密码。

What I have got is below. 我得到的是下面。 I have come close to implementing this but I am getting a weird grey background. 我已接近实现这一点,但我得到了一个奇怪的灰色背景。 How do I get rid of this grey background? 如何摆脱这种灰色背景?

在此输入图像描述

I think to remove gray background u should do one thing 我认为要删除灰色背景你应该做一件事

tableView.backgroundColor = [UIColor clearColor]; in viewDidLoad viewDidLoad

or if above code doesn't work try this. 或者如果上面的代码不起作用,试试这个。

tableView.backgroundView = nil;

I accomplish this with two lines: 我用两行来完成这个:

self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.backgroundView = nil;

Depending on the opacity you want you can also make sure of this: 根据您想要的不透明度,您还可以确保:

self.tableView.opaque = NO;
tableView.backgroundColor = [UIColor clearColor];

If you are using Interface Builder make sure you setup and connect your outlet for the tableView 如果您使用的是Interface Builder,请确保设置并连接tableView插座

You may want to call this method in viewDidLoad: 您可能想在viewDidLoad:调用此方法viewDidLoad:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM