简体   繁体   中英

How to highlight/change background color of table view section header while scrolling

I am stuck with displaying the table view section header. Problem is, when I scroll down, until I hit the next section header , I want my previous section header to be highlighted and as soon as I hit the next section header ,I want my this "new" section header to be highlighted and my previous section header to be unhighlighted . That, namely, means that I want the header which is displayed at the top to be highlighted while I scroll down and up.

To be more clear, I put related pictures:

1.当前节标题为“ Section 1” 1.Current section header is "Section 1" This occurs when app starts.

2.向下滚动但当前节标题仍然相同 2.Scrolled down but current section header is still same and should remain so until next section header commences.

3.向下滚动并传递到下一部分标题。

3.Scrolled down and passed to next section header. This section header should be highlighted since it is at the top of table view now. I put these pictures by taking snapshots and filling red color by using a painting tool. I hope it is clear to understand.

Perhabs you can do it with a trick?

Determine if a tableview cell is visible

Just take a look which cells are visible. If a cell of section 2 is visible but no cell of section 1, you know section 2 is at the top.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM