How do I get a UICollectionViewCell to be the full width of the device?


I have a UIView inside my UICollectionViewCell that I need to be reproduced. I need this view to be pinned to the left and right of the screen. However, I can't find any way to control the width of the UICollectionViewCell.

Am I just missing something?

You're right. UICollectionViewCell doesn't play by the same AutoLayout rules as other views. Each cell is controlled by a layout class set on the UICollectionView.

Technically, you can drag the handles in Interface Builder and resize that way but it won't be dynamic for different screen widths and orientations.

I can think of two options:

  1. Override the sizeForItemAtIndexPath: in the view controller and set to width of parent container programmatically. See Update 1 on question here for how this is done or check out the Apple documentation here for more background information
  2. Consider using a UITableView if all cells will always be full width