Reputation: 1142
I am very new to Auto Layout and generally to the iOS development. I am trying to find the best way how to make the SuperView's height dependent on subviews heights.
SuperView
--SubView1
--SubView2
--SubView3
Is this possible to do it directly in the UI builder or does it have to be done from the controller? Also some examples would be very much appreciated.
Upvotes: 1
Views: 258
Reputation: 4174
You can definitely do this in InterfaceBuilder. The concept is the same in Xcode 7 beta vs Xcode 6.x but the UI changes a bit.
The edges of your subviews should be "pinned" to the edges of the superview, and constrained in a relationship to each other as well.
To start out and get a feel for it, try a single subview of a different color, inset a fixed distance from the edges of the superview.
Upvotes: 2
Reputation: 10060
you can do it by code way:
//assuming that view is the superView
var height = CGFloat(0);
for subView : UIView in view.subviews as! [UIView]{
height+=subView.bounds.height;
}
view.frame.size.height = height;
Upvotes: 1