Reputation: 1396
I have a horizontal UICollectionView
, and each cell holds a UIImageView
. When I position the UIImageView inside the cell:
the storyboard looks like this(notice the UIImageView
takes the entire space of the UICollectionViewCell
with an identifier postInnerCell)
I think I have set the constraint using autoLayout correctly, with each side of the UIImageView
pined to the margins of the UICollectionViewCell
. Like this:
When I ran the simulator, however, it looks like this:
The image does not fill up the entire space of the collectionViewCell
(with the gray background color). The the content mode of the UIImageView
is set to be aspect fill in the interface builder.
**Note that the entire UICollectionView
is a cell of the tableView(Basically, what I try to accomplish is each row of the tableView is a horizontal slider). I'm not sure that's the problem. Anyone have any idea about why such a issue occurs. **
Upvotes: 1
Views: 1269
Reputation: 1396
It turns out that I need to re-layout the subview by calling cell.layoutIfNeeded()
before I return the cell in the collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath)
method. Thanks to the contribution of answer here UICollectionViewCell content wrong size on first load
Upvotes: 3
Reputation: 2252
IIRC, the content view of the cell will resize without triggering AutoLayout, so you have to manually either trigger a layout pass (e.g. .needsLayout = true
or add constraints from the content view to the cell
Upvotes: 0