简体   繁体   English

自定义单元格背景清晰?

[英]Custom cell clear background?

I have a tableview in a view controller that is dynamically populated with data from a database. 我在一个视图控制器中有一个tableview,该控制器中动态填充了数据库中的数据。 Now I have set the tableview to be clear and it working correctly, but I have tried to set the cells to be clear to no avail ? 现在,我已将tableview设置为clear且可以正常工作,但是我尝试将cell设置为clear无济于事?

cell.backgroundColor = UIColor.clearColor()

That line has been placed in the cellForRowAtIndexPath function. 该行已放置在cellForRowAtIndexPath函数中。

This little extension should help you. 这个扩展可以为您提供帮助。

The idea is to set the backgorundView to clear too and not just the backgroundColor : 这个想法是将backgorundView设置为清除,而不仅仅是backgroundColor

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

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

Usage: 用法:

In the cellForRowAtIndexPath add the following line: cellForRowAtIndexPath添加以下行:

cell.setTransparent()

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

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