How to change font color of the title in grouped type UITableView?

前端 未结 6 1582
轮回少年
轮回少年 2020-12-13 03:55

I have a grouped type table view and it looks pretty cool.

But, if I change the background color of the table to black, the titles becomes unclear.

Is it pos

6条回答
  •  眼角桃花
    2020-12-13 04:23

    If you just need to change the color or font on the header, use tableView: willDisplayHeaderView: forSection:. Here is an example in swift:

    Swift v5:

    override public func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
    
        if let view = view as? UITableViewHeaderFooterView {
            view.backgroundView?.backgroundColor = UIColor.blue
            view.textLabel?.backgroundColor = UIColor.clear
            view.textLabel?.textColor = UIColor.white
        }
    }
    

    Original:

    override func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
    
        if let view = view as? UITableViewHeaderFooterView {
            view.backgroundView?.backgroundColor = ThemeBlue
            view.textLabel.backgroundColor = UIColor.clearColor()
            view.textLabel.textColor = UIColor.whiteColor()
        }
    
    }
    

提交回复
热议问题