I have a UIViewController with a UICollectionView created inside it programmatically. I want to add a button to the cell:
viewDidLoad:
Add your button as a subview of cell.contentView
. Also, don't create the button every time collectionView:cellForItemAtIndexPath:
is called. You might be reusing an existing cell that already has a button. Better to add the button in your custom cell's init
method instead. Then just hide the button when you don't need it.