问题描述
我有一个显示照片的 UICollectionView
。我使用 UICollectionViewFlowLayout
创建了集合视图。它工作得很好,但我希望在边距上有间距。是否可以使用 UICollectionViewFlowLayout
来实现,或者我必须实现自己的 UICollectionViewLayout
?
I have a UICollectionView
which shows photos. I have created the collectionview using UICollectionViewFlowLayout
. It works good but I would like to have spacing on margins. Is it possible to do that using UICollectionViewFlowLayout
or must I implement my own UICollectionViewLayout
?
推荐答案
您可以使用集合视图:布局:insetForSectionAtIndex:
UICollectionView的方法
或设置附加到 UICollectionViewFlowLayout 对象的 sectionInset
属性> UICollectionView :
You can use the collectionView:layout:insetForSectionAtIndex:
method for your UICollectionView
or set the sectionInset
property of the UICollectionViewFlowLayout
object attached to your UICollectionView
:
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
return UIEdgeInsetsMake(top, left, bottom, right);
}
或
UICollectionViewFlowLayout *aFlowLayout = [[UICollectionViewFlowLayout alloc] init];
[aFlowLayout setSectionInset:UIEdgeInsetsMake(top, left, bottom, right)];
这篇关于UICollectionView间距边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!