UICollectionView - Change Location of Header

余生长醉 提交于 2020-01-04 14:07:05

问题


I have a UICollectionView that is using UICollectionViewFlowLayout to print a grid of cells to the screen. I configured the layout to flow horizontally & now I need to add a header to each section.

My main issue is with the location of the header which is to the left of the section while I want it to be on top of the section (similar to what it would be if the layout was configured to flow vertically).

Is there a way to do that short of creating my own UICollectionViewFlowLayout subclass? and if that's the only way, can someone please point out a good resource on collection views, it seems that most of the tutorials out there are pretty basic.

The solution discussed here only doesn't seem to work and the header still appears to the left of the section.


回答1:


Not sure if you've already found a solution but since I didn't find an acceptable answer on stack overflow I thought I'd contribute. The only way that I was able to get the header to lie above the cell was to write my own custom layout that inherited from UICollectionViewFlowLayout. The only thing you'll have to do is override the prepareLayout method so that your header is placed in the position that you want it.



来源:https://stackoverflow.com/questions/16433007/uicollectionview-change-location-of-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!