Last Cell in UICollectionView is clipped
clipped, ios, uicollectionview, uicollectionviewcell, xib
Solution
Ran into similar issue, I have horizontal `collectionView` with one row that I use in many places, somehow In one ViewController `collectionView` was clipping half of last cell also that cell wasn't clickable.
I was able to easily fix this by setting `sectionInset` of `collectionView`.
Just put this code in `viewDidLoad()` if your collectionView is in ViewController or `init` method if it's in xib.
if let flowLayout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
flowLayout.sectionInset.right = flowLayout.itemSize.width / 2
}
In my case missing empty space in `collectionView.contentSize` was nearly equal to half of cell width, but you can set it to whatever you want.
I used `.right` property because I scroll cells horizontally, in case of vertically scrolled `collectionView` just use `.bottom` property.
Not very pretty fix, but at least it works.
Problem
I have a UICollectionView that displays a vertical list of cells. It's basically a tableview but I'm using the collection view for more controller of how each cell is placed in the view. For some reason, the last cell in the collection view is clipped. I can drag up to see the bottom half, but as soon as I let go the collection view bounces back into place, obscuring the bottom half of the last cell. I have a xib that contains the collectionview, and then I register collection view cells from another xib. This whole view is placed in a navigation controller programmatically. My thoughts are that it has to be an issue with autolayout. Since I'm adding the view controller containing the collection view to a navigation controller programmatically, no constraints are set between the collection view and the navigation bar. If I hide the instantiated navigation bar and just drag one out in IB, the collection view cell is not clipped. But I don't want to do it this way. I've tried programmatically adding constraints, but that doesn't work either. Does anyone have any suggestions? Here's how I'm creating the navigation controller and placing the view controller containing the collection view into it. Also, the code I've tried to use to add constraints is include. For the time being, I'm doing this in the app delegate in didFinishLaunchingWithOptions: ``` self.homeViewController = [[FFHomeViewController alloc] init]; FFNavigationPanelViewController *navigationController = [[FFNavigationPanelViewController alloc] init]; UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:self.homeViewController]; // frontNavigationController.navigationBarHidden = YES; UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:navigationController]; NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:self.homeViewController.collectionView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.homeViewController.navigationController.navigationBar attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0]; [self.viewController.frontViewController.view addConstraint:topConstraint]; ```