Reputation: 41
Context
I am trying to create something similar to a Table view
using UICollectionView
.
I am using Xcode7
and storyboarding.
The way I do it is that I drag the collection view across the entire controller view.
And then I drag the entire cell across the row and align it with the right and left boundaries.
Problem
Question
How do I ensure that the width of the collection view cell matches that of the container width?
Upvotes: 1
Views: 928
Reputation: 5477
It is because you are not using autolayout. You can achieve this entirely in storyboard or through code. Using Storyboard
Upvotes: 0
Reputation: 5326
1) Implement the function of cell size and return the collection width:
-(CGSize) collectionView: (UICollectionView*) collectionView layout:(UICollectionViewLayout*) collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath*) indexPath {
CGFloat height = 50; //set the wanted height
return CGSizeMake(collectionView.frame.size.width,height);
}
2) Reload the collection when the screen size change (i.e. orientation change).
Upvotes: 1