Auto Layout in UICollectionViewCell not working
Well, I just looked on the iOS developer forums. Apparently, this is a bug with the iOS 8 SDK running on iOS 7 devices. The workaround is to add the following to your subclass of UICollectionViewCell:
- (void)setBounds:(CGRect)bounds { [super setBounds:bounds]; self.contentView.frame = bounds;}
override var bounds: CGRect { didSet { contentView.frame = bounds }}
Equivalent Swift Code :
override var bounds: CGRect { didSet { contentView.frame = bounds }}
Here is the solution, if you are not subclassing UICollectionViewCell
. Just add this two lines under your cellForItemAtIndexPath:
after dequeueReusableCellWithReuseIdentifier:
Obj-C
[[cell contentView] setFrame:[cell bounds]];[[cell contentView] setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
Swift - 2.0
cell.contentView.frame = cell.boundscell.contentView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]