Mert Mert - 1 year ago 174
iOS Question

UICollectionView spacing margins

I have a

which shows photos. I have created the collectionview using
. It works good but I would like to have spacing on margins. Is it possible to do that using
or must I implement my own

Answer Source

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)];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download