UITableView titleForHeaderInSection shows all caps

前端 未结 14 926
孤独总比滥情好
孤独总比滥情好 2021-01-30 16:28

I am using titleForHeaderInSection to show a header for a UITableView section. It worked fine with the iOS6 SDK, but the iOS7 SDK shows the header in all CAPS.

I guess

14条回答
  •  一生所求
    2021-01-30 17:16

    SWIFT

    In implementation, i found out that you need to specify section header text in both titleForHeaderInSection & willDisplayHeaderView function, othervise header hides.

        extension ViewController: UITableViewDelegate, UITableViewDataSource {
    
            func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
                let sectionHeader =  datasource[section].sectionHeader  
    
                // Header Title
                return sectionHeader 
            }
    
            func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
    
                guard let header = view as? UITableViewHeaderFooterView else { return }
                header.textLabel?.textColor = UIColor.darkGray
                header.textLabel?.font = UIFont.systemFont(ofSize: 20, weight: .semibold)
                header.textLabel?.frame = header.frame
    
                // Header Title
                header.textLabel?.text = datasource[section].sectionHeader
            }
    
        }
    

提交回复
热议问题