自定义细胞清晰背景?

时间:2015-10-14 10:11:58

标签: ios swift uitableview

我在视图控制器中有一个tableview,它使用数据库中的数据进行动态填充。现在我已经将tableview设置为清晰且工作正常,但我试图将单元格设置为清晰无效?

cell.backgroundColor = UIColor.clearColor()

该行已放置在cellForRowAtIndexPath函数中。

1 个答案:

答案 0 :(得分:1)

这个小小的延伸可以帮助你。

我们的想法是将backgorundView设置为清除,而不仅仅是backgroundColor

extension UITableViewCell {
    func setTransparent() {
        let bgView: UIView = UIView()
        bgView.backgroundColor = .clearColor()

        self.backgroundView = bgView
        self.backgroundColor = .clearColor()
    }
}

用法:

cellForRowAtIndexPath添加以下行:

cell.setTransparent()