Search code examples
iosuitableviewuicollectionviewuicollectionviewcelllayoutsubviews

In layoutSubviews cell bounds or frame should be set?


I am afraid to set cell's frame in layoutSubviews, because I know I want to place cell into 0 origin.x position, but I am not sure about origin.y position. But sometimes set only the bounds so the size of the cell, has strange effect, i.e. cell 'moves out' from collectionView.

What do you set frame or bunds in layoutSubviews?


Solution

  • Not sure that setting frame manually is good idea for UICollectionViewCell/UITableViewCell subclasses. I believe such approach can influence private behavior of UICollectionView/UITableView and break their usual layout.

    I think it should be implemented in use datasource and delegate methods only (+ UICollectionViewLayout). Sometimes you can change superview frame to get the expected effect.