Limitations not updated in subclass of UICollectionViewCell on iOS7

I have a collection based layout with different cell sizes depending on the content. A normal cell is 200x200 pixels, but if there is no content, I display a cell with the same size as the collection itself.

I use

- (CGSize)collectionView:(UICollectionView *)collectionView
                  layout:(UICollectionViewLayout *)collectionViewLayout
  sizeForItemAtIndexPath:(NSIndexPath *)indexPath

to calculate the correct size.

Be that as it may, my children in the cell do not update its restrictions. The cell is really simple, just UILabel, which should be concentrated inside the supervisor. I have horizontal and vertical centered constraints (also tried to snap each edge to the superwine). The result is that subviews gets the same size and position as in the Builder (Storyboard) interface.

I set the background colors for both the cell and the label, and I see that the cell is getting the correct size, but not on the label.

The problem exists only in iOS7 and works the same way as in iOS8.

Please, help!

screenshot

+4
source share
2 answers

Thank you, a panel of questions related to data flow. Found this thread and it solved my problem.

Auto layout in UICollectionViewCell not working

I put this in my subclass of UICollectionViewCell:

- (void)setBounds:(CGRect)bounds {
    [super setBounds:bounds];
    self.contentView.frame = bounds;
}
+11
source

For me, when these problems occur on iOS9 with fast 2. I just called awakeFromNib()and installed autoresizingMaskin UICollectionViewCell.

My UICollectionViewCell looks like this:

override func awakeFromNib() {
   self.contentView.autoresizingMask = [UIViewAutoresizing.FlexibleWidth , UIViewAutoresizing.FlexibleHeight]
}
+3
source

All Articles