swift ios 8 change font title of section in a tableview

前端 未结 11 1618
夕颜
夕颜 2021-01-31 08:29

I would like to change the font type and font size of a section header in a table view controller.

My code:

func tableView(tableView: UITableView, willDi         


        
11条回答
  •  不知归路
    2021-01-31 09:00

    Swift 3

        override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
                let headerView = UIView()
                headerView.backgroundColor = UIColor.lightGray
    
                let headerLabel = UILabel(frame: CGRect(x: 30, y: 0, width:
                    tableView.bounds.size.width, height: tableView.bounds.size.height))
                headerLabel.font = UIFont(name: "Verdana", size: 20)
                headerLabel.textColor = UIColor.white
                headerLabel.text = self.tableView(self.tableView, titleForHeaderInSection: section)
                headerLabel.sizeToFit()
                headerView.addSubview(headerLabel)
    
                return headerView
            }
    
        override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
            return 40
        }
    

提交回复
热议问题