I have a UICollectionViewController
using a UICollectionViewFlowLayout
where my itemSize
is the size of the UICollectionView
In my case I have to reduce bottom inset (from 20 to 0) of cell as I have reduced 20 from height of collectionview From
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
- return UIEdgeInsets(top: 10, left: 10, bottom: 20, right: 10)
+ return UIEdgeInsets(top: 10, left: 10, bottom: 0, right: 10)
}
func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath) -> CGSize {
let size = CGSize(width: 350, height: collectionView.bounds.size.height - 20)
return size
}
This way had worked for me perfectly!.
I just subtracted the top and bottom insets from the view's height as said in that error.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: view.frame.width , height: view.frame.height - (view.safeAreaInsets.top + view.safeAreaInsets.bottom))
}
I hope it helps!
iOS 11 update: automaticallyAdjustsScrollViewInsets
is deprecated in iOS 11.0.
Apple recommends using UIScrollView
's contentInsetAdjustmentBehavior
method instead. I set this value to .never
and the error has gone. You can also set this property in Interface Builder.
ios 10: topmost view was not connected to the view outlet