Changing Font Size For UITableView Section Headers

前端 未结 11 793
借酒劲吻你
借酒劲吻你 2020-12-12 09:28

Can someone please instruct me on the easiest way to change the font size for the text in a UITableView section header?

I have the section titles implemented using t

11条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-12 09:55

    Swift 2:

    As OP asked, only adjust the size, not setting it as a system bold font or whatever:

    func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
            if let headerView = view as? UITableViewHeaderFooterView, textLabel = headerView.textLabel {
    
                let newSize = CGFloat(16)
                let fontName = textLabel.font.fontName
                textLabel.font = UIFont(name: fontName, size: newSize)
            }
        }
    

提交回复
热议问题