I am trying to make the spacing between my cells = 5
In the iPhone 4s the UICollectionViewCell becomes a square but I need rectangle.
I need iPhone4s iPhone5 iPhone6 iPhone 6Plus the cell, but the width and height of the cell is always wrong. I don't know how to do it automatically.
This is my code:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(([UIScreen mainScreen].bounds.size.width - 20) /2, ([UIScreen mainScreen].bounds.size.height) /3);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(5, 5, 5, 5);
}
What am I missing? Thanks in advance!
some change in your code will works fine
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
int itemWidth=([UIScreen mainScreen].bounds.size.width - 20)/2;
int intemHeight=itemWidth*2/3;
return CGSizeMake(itemWidth, intemHeight);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.