gpt4 book ai didi

ios - 如何以编程方式启用/禁用 UICollectionView 中的节标题?

转载 作者:IT王子 更新时间:2023-10-29 07:45:59 24 4
gpt4 key购买 nike

如何以编程方式启用/禁用 UICollectionView 中的节标题?

它可以很容易地在 Storyboard(复选框)中轻松完成,但如何在代码中完成呢?

最佳答案

您可以使用 UICollectionViewDelegateFlowLayoutcollectionView:layout:referenceSizeForHeaderInSection: 方法并返回 CGSizeMake(0,0) 或进行相应设置UICollectionViewFlowLayoutheaderReferenceSize

编辑:headerReferenceSize 实际上是 Storyboard用来显示/隐藏标题的属性。我已经添加了 Storyboard文件中的相关行

部分复选框开启:

 <collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="xAt-Uo-bMl">
<size key="headerReferenceSize" width="50" height="50"/></collectionViewFlowLayout>

部分复选框关闭

 <collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="xAt-Uo-bMl">
<size key="headerReferenceSize" width="0" height="0"/></collectionViewFlowLayout>

编辑#2:

来自 the official docs :

Each section in a flow layout can have its own custom header and footer. To configure the header or footer for a view, you must configure the size of the header or footer to be non zero. You can do this by implementing the appropriate delegate methods or by assigning appropriate values to the headerReferenceSize and footerReferenceSize properties. If the header or footer size is 0, the corresponding view is not added to the collection view.

关于ios - 如何以编程方式启用/禁用 UICollectionView 中的节标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24558772/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com