更改空表格视图单元格的颜色?

时间:2014-05-27 02:39:08

标签: ios uitableview

我从故事板中更改了单元格的颜色(没有使用任何代码),但正如您在此图片中看到的那样:

enter image description here

默认情况下,空单元格保持白色。我想将那些空单元格改为红色,但我无法搞清楚。 我也在我的代码设置cell.backgroundColor = [UIColor redColor];中没有成功。

4 个答案:

答案 0 :(得分:3)

您只需设置tableView的backgroundColor: yourTableView.backgroundColor = [UIColor redColor];

答案 1 :(得分:2)

对于喜欢使用Storyboard的其他人来说,没有特定的设置来设置它,但是在Storyboard的Table View中,您可以转到Identity Inspector,输入" backgroundColor"并将其设置为用户定义的运行时属性中的颜色类型:

enter image description here

不确定为什么这不是故事板中的设置,但这有效!

答案 2 :(得分:1)

在Swift 3中你可以这样做:

self.tableView.backgroundColor = UIColor.red

答案 3 :(得分:1)

XCODE 8.2和SWIFT 3

要更改tableview的颜色,您可以使用以下两种方式:

  1. 使用(TableViewController):您可以调用TableView并通过代码更改颜色。

    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.backgroundColor = UIColor.red
    
    }
    
  2. 使用(StoryBoard):选择您的TableView,然后在检查器中点击Atributes,然后在向下视图中找到View Section并从Background atribute中选择您想要的颜色。

  3. enter image description here

相关问题