UITableView - change section header color

前端 未结 30 2814
不思量自难忘°
不思量自难忘° 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:32

    I know its answered, just in case, In Swift use the following

        override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
            let tableViewWidth = self.tableView.bounds
    
            let headerView = UIView(frame: CGRectMake(0, 0, tableViewWidth.size.width, self.tableView.sectionHeaderHeight))
            headerView.backgroundColor = UIColor.greenColor()
    
            return headerView
        }
    

提交回复
热议问题