I have a single row collectionview
that scrolls horizontally. The collectionview
works but it cuts off the second to last cell (labeled orange) and hides the last cell.
I have 5 cells, each of size 166x166. I have checked the contentsize
of the viewlayout
and it's width is 830 which is correct, yet I am unable to scroll that far.
Here is the settings in Storyboard:
And here is the code for the collectionview
.
#pragma mark Collection View Methods
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [array count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"FeaturedCell" forIndexPath:indexPath];
UILabel *label = (UILabel *) [cell viewWithTag: 100];
label.text = [array objectAtIndex:indexPath.row];
[cell.layer setBorderWidth:2.0f];
[cell.layer setBorderColor:[UIColor whiteColor].CGColor];
return cell;
}
The new IB default for view sizes is 600 points. If you don't use auto layout or another means to constrain the sizes, the frame will extend off screen and won't be visible. If this is happening at 320 px wide, you'll lose 240 points, which if your cells are 166 points wide, means you lose about 1 1/2 cells. About what's missing.
Make sure the collection view has a trailing constraint with constant 0 to the superview edge (or other means to ensure the sizes match, such as "equal" widths to superview).
Setting minimumLineSpacing
and minimumInteritemSpacing
to an equal value solved my problem for horizontal collection view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With