Autolayout height equal to MAX(multiple view heights)
Say I have a view called
container contains 5
UIButtons. I want to add a height
container, and this height should be equal to the
NSLayoutHeightAttribute of the tallest button in its subviews.
I don’t see a straightforward way to do this. Anyone have any ideas?
- Where to add topLayoutGuide constraint code
- iOS8 self-sizing static TableView cells with Interface Builder
- Autolayout resize button based on text and have textfield fill available space
- Self sizing Cells,. Autolayout and hidden UIViews
- Dynamic UITableViewCell content does not expand cell
- iOS: Multi-line UILabel in Auto Layout
Solutions Collect From Internet About “Autolayout height equal to MAX(multiple view heights)”
You need one constraint for each subview (button), specifying that the container’s height should be greater than or equal to the subview’s height. Give that constraint a high priority, like
UILayoutPriorityRequired (which is the default anyway).
Then add one more constraint on the container’s height, specifying that it should have a height equal to zero. Give that constraint a low priority, like
UILayoutPriorityLow. Since auto layout tries to minimize the error of unsatisfied constraints, it will make the container as short as possible while still satisfying all higher-priority constraints.
I have put an example in this gist. It produces this result:
The blue views have fixed heights. The tan view is the superview of the blue views and its height is constrained as I described above. I pinned each subview’s bottom to the container’s bottom, but you could pin the tops or the Y centers instead.
- How to get street address from ABPeoplePickerNavigationController
- With Data (not NSData), in fact how actually do you make a utf8 version of a jpeg?
- Best way to achieve UILabel animation effect in Swift?
- Blur specific part of an image (rectangular, circular)?
- Custom view created with Interface Builder does not render when called in other views
- Swift 3 URLSession.shared() Ambiguous reference to member 'dataTask(with:completionHandler:) error (bug)
- How to convert SubView's Frame Coordinate System to Self View's Coordinate System
- iOS simulator for iPhone 5- 1136 x 640 resolution
- Swift AVPlayerItem close when finished
- Is there any way of locking an object in Swift like in C#
- NSDateFormatter milliseconds bug
- Reference as key in swift dictionary
- How to animate the NSSplitView while resizing?
- Good example code for Objective-C