简体   繁体   中英

Swift4: How to change UITableView cell color

I have a UITable view where you can add items by pressing a button. I want its cells to be clear, I already made its background semitransparent, but once you click on the button that allows you to save the items in it, the first you save has a white background. Then, if you press the button other times, all of the cells, except for the last created, become semitransparent, but one continues to be white. This is my code, how could I make it completely clear?

extension ViewController : UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return number.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let textCell = tableView.dequeueReusableCell(withIdentifier: "WordCell", for: indexPath)
        textCell.textLabel?.text = "\(indexPath.row + 1)         \(number[indexPath.row])"
        let semitransparentBlack = UIColor(rgb: 0x000000).withAlphaComponent(0.3)
        textCell.layer.backgroundColor = semitransparentBlack.cgColor
        textCell.textLabel?.layer.backgroundColor = semitransparentBlack.cgColor
        textCell.textLabel?.textColor = UIColor.white
        return textCell

    }


}

您可以使用textCell.backgroundColor = semitransparentBlack设置颜色

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