ios swift5 let tableHeaderView automatically row height tableHeaderView adaptive height according to content

  • There is no parent view before headView, and there is no need to set frame
  • Make the layout of the subview in the headView can give him a certain height
  • Then call the following code and it's ok (my own test is valid)
 let size = headView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
 let rect = CGRect(x: 0, y: 0, width: 0, height: size.height)
 headView.frame = rect
 tableView.tableHeaderView = contentView

Reference blog:
tableHeaderView adaptive height - short book

Guess you like

Origin blog.csdn.net/baidu_40537062/article/details/123900957