0

I have created collection view cell via storyBoard,for the 4 and 5 inch screen i have set the UIEdgeInsetsMake as programatically,if the device is not 4 and 5,then my storyboard UIEdgeInsetsMake have to set for that.

How to do it?

This is my code

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView
                        layout:(UICollectionViewLayout*)collectionViewLayout
        insetForSectionAtIndex:(NSInteger)section {
    CGRect screenBound = [[UIScreen mainScreen] bounds];
    CGSize screenSize = screenBound.size;
    CGFloat screenWidth = screenSize.width;
    UIEdgeInsets insets= UIEdgeInsetsMake(?,?,?,?);//how to get the current edge insets.
    if(screenWidth==320)
    {
        UIEdgeInsets insets = UIEdgeInsetsMake(0,12,20,2);
        return insets;
    }
        return insets;
}
Kishore Kumar
  • 4,265
  • 3
  • 26
  • 47

1 Answers1

1

You're looking for the contentInset property.

Also, you're re-declaring the variable insets in your code. Consider changing to the following for simplicity:

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView
                    layout:(UICollectionViewLayout*)collectionViewLayout
    insetForSectionAtIndex:(NSInteger)section {

    if([UIScreen mainScreen].bounds.size.width == 320)
    {
        return UIEdgeInsetsMake(0,12,20,2);
    }

    return collectionView.contentInset;

}
Stonz2
  • 6,306
  • 4
  • 44
  • 64