Swift - how to make custom header for UITableView?

后端 未结 7 803
说谎
说谎 2020-12-23 13:57

I need to add custom header to my table

I try this

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

    l         


        
7条回答
  •  忘掉有多难
    2020-12-23 14:20

    Did you set the section header height in the viewDidLoad?

    self.tableView.sectionHeaderHeight = 70
    

    Plus you should replace

    self.view.addSubview(view)
    

    by

    view.addSubview(label)
    

    Finally you have to check your frames

    let view = UIView(frame: CGRect.zeroRect)
    

    and eventually the desired text color as it seems to be currently white on white.

提交回复
热议问题