Reputation: 11
I have a collectionview that is full width of the screen, but I want the collectionview and the collectionview cell to adjust size according to the iPhone screen.
One cell takes up the collectionview and scrolls across.
So I want the cell and collectionview to be 320 x 125 for iPhone 4, 4s, 5, and 5s; 375 x 146 for iPhone 6 and 414 x 162 for iPhone 6 Plus.
It wasn't possible to use autolayout on the cell but I was able to for the collectionview.
Any help is appreciated.
Thanks
Upvotes: 2
Views: 3630
Reputation: 175
Maybe this will help! I put in this post - How to scale cells dynamically and proportionally depending on device screen!!!
UICollectionView cells not horizontal after rotation
Upvotes: 0
Reputation: 3494
You could implement the delegate method for the cell size
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;
You can return there the size you want.
What I did not really understand from your question was if the collection view already has the size you want. If so, in the delegate method you could do something like:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(CGRectGetWidth(self.collectionView.frame), CGRectGetHeight(self.collectionView.frame));
}
With this the cells should have the right size.
Hope this helps!
Upvotes: 2
Reputation: 11839
While defining frame of UICollectionView
or UICollectionViewCell
, define width
frame value as self.view.frame.size.width
.
It will automatically pick the full width which you want.
Upvotes: 0