UICollectionView间距边距 [英] UICollectionView spacing margins

查看:853
本文介绍了UICollectionView间距边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示照片的 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间距边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆