Reputation:
I'm trying to display a button in a collection view, but it's not showing when I run it on the iphone simulator; however it clearly shows in the storyboard (refer to image). Also - I notice that when I add horizontal and vertical constraints it shows. When i delete the constraints however, the button completely disappears. Shouldn't some of the button display in the collection view since my coordinates don't seem to be off enough for the entire button to not display? Sorry if this is a lousy question - I just picked up ios development.
Upvotes: 0
Views: 188
Reputation: 16341
Your UIButton
seems to be getting smaller due to the auto-resizing of UICollectionViewCell
. To fix the issue you can either set the itemSize
property of the collectionViewLayout
or by returning the sizeForItem
if you're giving different size for each cell. Here's the code:
let flowLayout = UICollectionViewFlowLayout()
flowLayout.itemSize = CGSize(width: collectionView.frame.width, height: 300)
collectionView.collectionViewLayout = flowLayout
Here's how you add it via Size Inspector
:
Collection View Flow Layout
on the leftsize inspector
tab on the right you can give Cell Size
.Upvotes: 1