A bit late to the party here, but I came across a couple solutions
The right way (scroll to first cell):
https://coderwall.com/p/e-ajeq/uicollectionview-set-initial-contentoffset
Simple hacky way:
I add in a transparent "spacer" cell to the first item to offset the rest of the cells.
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionCell", for: indexPath)
if (indexPath.row == 0) {
cell.backgroundColor = UIColor.white
return cell
}
cell.backgroundColor = UIColor.green
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if (indexPath.row == 0){
//spacer
return CGSize(width:6, height:50)
}
return CGSize(width: 50, height: 50)
}