UITableView - change section header color

前端 未结 30 2893
不思量自难忘°
不思量自难忘° 2020-11-27 08:50

How can I change color of a section header in UITableView?

EDIT: The answer provided by DJ-S should be considered for iOS 6 and above. The accepted

30条回答
  •  生来不讨喜
    2020-11-27 09:19

    Based on @Dj S answer, using Swift 3. This works great on iOS 10.

    func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
        // Background color
        view.tintColor = UIColor.black
    
        // Text Color
        let headerView = view as! UITableViewHeaderFooterView
        headerView.textLabel?.textColor = UIColor.white
    }
    

提交回复
热议问题