Is it possible to set UICollectionViewFlowLayout object attributes directly without touching UICollectionViewDelegateFlowLayout protocol?
For example, if I want every item size to be the same, could I just do this:
self.collectionViewFlowLayout.itemSize = CGSizeMake(100,100)
instead of this:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(100, 100);
}
If positive, how can I reference the UICollectionViewFlowLayout object?
If negative, could you explain why Apple choose to make it a protocol? It obviously requires more code.
Yes, it is possible, but not by accessing an existing UICollectionViewFlowLayout instance. You need to subclass UICollectionViewFlowLayout and handle all of the attributes that you’d like to in your subclass.
There were some great WWDC sessions on that this year, and I recommend watching them. You can see Session 205 here (login required) and Session 219, here(login required). The second video will address your question directly.