Resize UICollectionView Height

I am trying to resize a UICollectionView by setting it to 0 when loading the view controller, and then increasing its size using animation when the button is clicked. I tried several different things, but it does not change at all. Here are all the different things that I tried to change to a height of 0:

CGRect bounds = [self.collectionView bounds]; [self.collectionView setBounds:CGRectMake(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height - 100)]; 

....

 CGRect frame = [self.collectionView frame]; [self.collectionView setFrame:CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height - 100)]; 

....

 CGRect frame = self.collectionView.frame; frame.size.height -= 100; self.collectionView.frame = frame; 

....

  self.collectionView.clipsToBounds = YES; self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleHeight; 
+8
xcode resize uicollectionview cgrect
source share
2 answers

If you use the Builder interface to initialize the UICollectionView, disable the "Use autorun" option from the File Inspector in the xib file where your CollectionView is created. You can then change the height using the setFrame or setBounds methods.

+4
source share

You can avoid disabling the Autolayout function by creating a socket to limit the height and then adjust the limit constant in the code.

Exit

 @IBOutlet weak var collectionViewVerticalConstraint: NSLayoutConstraint! 

Customization

 collectionViewVerticalConstraint.constant = 0 
+2
source share

All Articles