I want to put a UICollectionView control that shows thumbs horizontally (only a single line of thumbs). For some reason the UICollectionView push the thumbs 44 pixels down,
As some others mentioned, viewController.automaticallyAdjustsScrollViewInsets
has been deprecated since iOS 11. My solution...
Swift 4.2, Xcode 10.1, iOS 12.1:
For some reason, collectionView.contentSize.height
was appearing smaller than the resolved height of my collection view. First, I was using an auto-layout constraint relative to 1/2 of the superview's height. To fix this, I changed the constraint to be relative to the "safe area" of the view.
This allowed me to set the cell height to vertically fill my collection view using collectionView.contentSize.height
:
private func setCellSize() {
let height: CGFloat = (collectionView.contentSize.height) / CGFloat(numberOfRows)
let width: CGFloat = view.frame.width - CGFloat(horizontalCellMargin * 2)
let layout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
layout.itemSize = CGSize(width: width, height: height)
}
Before
After