mrgrieves
mrgrieves

Reputation: 579

UICollectionViewCell ignores specified size but respects origin

I have a collection view with a custom layout. iOS 8 is working fine, but in iOS 7 the cells are ignoring the width/height they're assigned by the layout and just keep the size they got from the xib.

My layout is setting layout attributes with the correct size, but the cells are ignoring it. Weirdly, the origin is being respected.

I'm using Xcode 6.0.1, the XIBs are built for iOS 7, and I am using autolayout in the cells.

Upvotes: 0

Views: 145

Answers (1)

Juraj Antas
Juraj Antas

Reputation: 2712

I know exactly what you are talking about. Had same issue like this.

Here is how to fix it: you need to add autoresizing yourself to the cell. For some reason it is not properly fetched from xib on iOS7 (when using xcode6)

Lets assume that you have cell defined in storyboard or xib file and you have implementation files for that cell. For this example call it MyCell.h and MyCell.m

To MyCell.m add this:

-(void)awakeFromNib
{
    [super awakeFromNib];

    self.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    self.contentView.translatesAutoresizingMaskIntoConstraints = YES;
}

Hope this helps ;)

Upvotes: 2

Related Questions