iosswiftuitableviewuitableviewsectionheader

How to dynamically change UITableView section header with scrolling. Or how to add a button to table section header?


The default behavior for UITableView section headers is to stick to the top edge of the table and slightly change background to a thin material.

I need to add a button to the section header, so, as I understand, I need to write my own custom header with the viewForHeaderInSection. How do I replicate the default behavior of changing the background to a thin material? How do I detect that the section header hit the top edge of the table and force to change the view's background?

Alternatively, how can I add a button to the standard header without writing my own?


Solution

  • Creating a simple subclass of UITableViewHeaderFooterView helped. It kept all the standard behavior and visuals, while I just added a button on top.