Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the minimum size of a UIView based on its constraints

I have created a custom nib and added it to my view hierarchy. The view separates to subviews using a constraint which is greater than or equal to, in other words, giving the view a minimum size to work with.

Is it possible to get the minimum size of a UIView from the constraints system?

like image 376
Adam Carter Avatar asked Jan 21 '26 10:01

Adam Carter


1 Answers

UIView has a method systemLayoutSizeFittingSize: to return the smallest size (or largest size) for a view.

CGSize smallestViewSize = [view systemLayoutSizeFittingSize: UILayoutFittingCompressedSize];

The UIView method intrinsicContentSize returns the most desired size. This size may be somewhat in the middle of the two sizes returned before.

Prior to iOS6, you would call sizeThatFits: to get a fitting size that may be smaller than the size passed in or was by default the bounds of the receiver.

like image 150
Fruity Geek Avatar answered Jan 24 '26 17:01

Fruity Geek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!