ORStudios
ORStudios

Reputation: 3233

How to adjust Autolayout positions of resizing UICollectionView?

I have the following setup where the UICollectionView positioned in between the two headers resizes to fit all its cells. It basically is a 2x2 layout in table format.

enter image description here

Now once the data is loaded I use the following to resize the UICollectionView.

- (void)loadContent {

[self.collectionViewAboutProperty reloadData];

[self.labelAddress setText:stringAddress];

float totRows = [self.dictAboutProperty count];

float cHeight = ceil(totRows/2.0);

float collectionHeight = (cHeight * 20) + (cHeight * 5);

[self.collectionViewAboutProperty setFrame:CGRectMake(self.collectionViewAboutProperty.frame.origin.x, self.collectionViewAboutProperty.frame.origin.y, self.collectionViewAboutProperty.frame.size.width, collectionHeight)];

}

The problem is that when the above happens it overlaps the bottom header. It is almost as if the Autolayout constraints on the bottom header are completely ignored. At the minute I have it set to a space of about 25pixels from the above UICollectionView

How can I make it so that when the content is loaded and the collection view is dymically resized the views below update themselves to meet the constraints?

Thanks

Upvotes: 0

Views: 60

Answers (1)

Rafeek
Rafeek

Reputation: 533

[self.labelAddress setText:stringAddress];

float totRows = [self.dictAboutProperty count];

    float cHeight = ceil(totRows/2.0);

    float collectionHeight = (cHeight * 20) + (cHeight * 5);

    [self.collectionViewAboutProperty setFrame:CGRectMake(self.collectionViewAboutProperty.frame.origin.x, self.collectionViewAboutProperty.frame.origin.y, self.collectionViewAboutProperty.frame.size.width, collectionHeight)];
    [self.collectionViewAboutProperty reloadData];

will solve your issue.

Upvotes: 1

Related Questions