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?
- Autolayout UILabel in UITableViewCell
- How do I set the height of tableHeaderView (UITableView) with autolayout?
- Autolayout Contraints for a View from XIB
- UILabel not wrapping text correctly sometimes (auto layout)
- Layout attributes relative to the layout margin on iOS versions prior to 8.0
- iOS 6.0 AutoLayout issue with constraints: subviews disappear when rotated
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.
- Does a project have to be created as a sprite kit or can the framework simply be added?
- PDF Generation Swift
- Library not loaded: @rpath/Alamofire.framework/Alamofire
- How do I locate the CGRect for a substring of text in a UILabel?
- How to create Custom UIAlertController in swift ios?
- Nested UIStackViews Broken Constraints
- how to change Application language on run time using Two Button in iphone SDK?
- What is this syntax when I was attempting to override a getter?
- Which scenes keyword “volatile” is needed to declare in objective-c?
- XCode 8.2.1 error – No such module YouTubePlayer
- Why can't I see the iOS 7.0 simulator in Xcode on Yosemite?
- How to change the font size of the text on a UISegmentedControl?
- UITextField causes crash in iOS 5, works fine in iOS 4
- Checking a Public Key in canAuthenticateAgainstProtectionSpace
- AudioHardware.cpp:1200:AudioObjectRemovePropertyListener: AudioObjectRemovePropertyListener: no object with given ID 0