I have a simple collection view on a ViewController. It is a single, horizontally-scrolling strip. There are unlimited number of cells that will either be of type A or B. Each class of cell has a different width (A=160, B=40).
So the collection array might be AABBABAABA and the collection view cell widths should alter according to the type of cell.
I've tried to set the cell widths in the attributes. I've tried determining the width to use via tags, isKindOfClass, tintColors, viewDidLoad etc. Nothing seems to work so I assume it's more complicated than first thought.
I have implemented the following but it always chooses 160 width since tag is always found to be nil. I think I am missing a layout or something?
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
if collectionView.cellForItemAtIndexPath(indexPath)?.tag == 111 {
return CGSize(width: 40, height: 80)
} else {
return CGSize(width: 160, height: 80)
}
}
The tag is recognised within the didSelectItemAtIndexPath function but seemingly not within the sizing function.
Anyone any ideas?
Thanks