3

So, it's better to post images to understand

IOS 8 IOS 7.1 IOS 7.0 IN storyboard

I did not use any constraints here, because, when I start using constraints, constraints warning is thrown. I set the size of the cell in storyboard (159/50), min spacing is 1, and also in code

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(159, 50);
}

Also i've set "Clip Subviews" at collectionview, collectionviewcell, view in cell and button in view to NO to see where the views were placed. "Autoresize subviews" does not do anything, i've checked. Mode of each view is set to "Scale to Fit". Size of the cell can be default or custom, this also does not make sense.

So, why this is happened? I've spent 2 days on this. Please help.


I've also attach screenshots with constraints on.

I've set top, bottom, leading and trailing constraints on UIView inside cell, and UILabel inside this UIView.

ios 8 ios 7.1 ios 7.0

but in this case I got constraints error on each device:

(
    "<NSLayoutConstraint:0x7fd0834b0b10 H:[UIButton:0x7fd0834b0140'Button']-(0)-|   (Names: '|':UIView:0x7fd0834b0050 )>",
    "<NSLayoutConstraint:0x7fd0834b0b60 H:|-(35)-[UIButton:0x7fd0834b0140'Button']   (Names: '|':UIView:0x7fd0834b0050 )>",
    "<NSLayoutConstraint:0x7fd0834b0dd0 H:|-(20)-[UIView:0x7fd0834b0050]   (Names: '|':UIView:0x7fd0834aff60 )>",
    "<NSLayoutConstraint:0x7fd0834b0e70 H:[UIView:0x7fd0834b0050]-(19)-|   (Names: '|':UIView:0x7fd0834aff60 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x7fd0834b27c0 h=--& v=--& H:[UIView:0x7fd0834aff60(50)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fd0834b0b10 H:[UIButton:0x7fd0834b0140'Button']-(0)-|   (Names: '|':UIView:0x7fd0834b0050 )>

I think this error occurs because cell size is not set correctly, in my case it is set to default 50x50, i've checked this.

All these problems have occurred after install xcode 6.


Funny thing: when I use UICollectionViewController, instead of UIViewController with UICollectionView inside with needed delegates on, my app is working correctly.


Rajesh
  • 10,318
  • 16
  • 44
  • 64
wtorsi
  • 692
  • 2
  • 8
  • 27
  • 3
    After weekend of searching the answer, i found what i need here http://stackoverflow.com/questions/24750158/autoresizing-issue-of-uicollectionviewcell-contentview-frame-in-storyboard-proto – wtorsi Sep 22 '14 at 07:22
  • Replace the comment as an answer to the question – iosMentalist Nov 18 '14 at 09:44

1 Answers1

1

You have to add the following code in the custom cell class:

-(void)awakeFromNib
{
    [super awakeFromNib]; 
    self.contentView.frame = self.bounds;
    self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}

Solution found in: Autoresizing issue of UICollectionViewCell contentView's frame in Storyboard prototype cell (Xcode 6, iOS 8 SDK) happens when running on iOS 7 only

Community
  • 1
  • 1
Jorge Irún
  • 1,683
  • 1
  • 15
  • 13