我正在尝试使用带有水平滚动的流布局来实现UICollectionView标头。我希望标题可以在集合视图的整个宽度上延伸,但高度要小。
我了解文档中指出,对于水平滚动方向,只有使用的宽度和高度会拉伸以填充整个集合视图。 (下面的代码中提供的第一种方法)
无论如何,我可以使用流程布局覆盖它吗?
我试图更改最小行距和边缘插图,但它们都不起作用。
任何帮助将不胜感激。谢谢!
// configure header size (flow layout delegate)
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
// only width is used for horizontal scrolling. (height only for vertical)
return CGSize(width: self.view.frame.width, height: self.view.frame.height/5)
}
// configure section line spacing
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return CGFloat(10)
}
// configure section edgeinsets
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 0, left: 0, bottom: 100, right: 100)
}
请找到随附的用户界面屏幕截图。
红色背景色为标题,并且当其宽度设置为等于集合视图的宽度时,当前占据整个集合视图(VC的子代)。
Collection view covered entirely by its header (red bg_colour).