如何更改 UICollectionView 中整个部分的背景颜色? [英] How to change background color of a whole section in UICollectionView?
本文介绍了如何更改 UICollectionView 中整个部分的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 UICollectionView 中,我想为整个部分提供统一的背景颜色,而不是为单个单元格或整个集合视图.
In UICollectionView, I want to give the whole section a uniform background color, instead of for a single cell or for the whole collection view.
我没有看到任何委托方法可以做到这一点,有什么建议吗?
I don't see any delegate method to do that, any suggestions?
推荐答案
iOS 13 中引入的新 UICollectionViewCompositionalLayout
有一个名为 decorationItems
的属性,可以方便地添加装饰项,它您可以使用为该部分添加背景.
The new UICollectionViewCompositionalLayout
introduced in iOS 13 have a property named decorationItems
for adding decoration items conveniently, which you could use to add a background for the section.
let section = NSCollectionLayoutSection(group: group)
section.decorationItems = [
NSCollectionLayoutDecorationItem.background(elementKind:"your identifier")
]
这篇关于如何更改 UICollectionView 中整个部分的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文