简体   繁体   中英

Custom cell clear background?

I have a tableview in a view controller that is dynamically populated with data from a database. 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 ?

cell.backgroundColor = UIColor.clearColor()

That line has been placed in the cellForRowAtIndexPath function.

This little extension should help you.

The idea is to set the backgorundView to clear too and not just the 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:

cell.setTransparent()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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