I have a view inside a view:
+--------------+
| |
| +-----+|
| | ||
| +-----+|
+--------------+
I’d like the inner view to always start right in the middle of the outer view horizontally, and span the whole remaining half to the right edge:
innerView.frame.size.width = outerView.frame.size.width/2;
innerView.frame.origin.x = outerView.frame.size.width/2;
How can I express that using auto layout?
Stack views let you leverage the power of Auto Layout, creating user interfaces that can dynamically adapt to the device's orientation, screen size, and any changes in the available space. The stack view manages the layout of all the views in its arrangedSubviews property.
Auto Layout defines margins for each view. These margins describe the preferred spacing between the edge of the view and its subviews. You can access the view's margins using either the layoutMargins or layoutMarginsGuide property.
In general, the intrinsic content size simplifies the layout, reducing the number of constraints you need. However, using the intrinsic content size often requires setting the view's content-hugging and compression-resistance (CHCR) priorities, which can add additional complications.
You actually can do this in IB/Storyboards as far back as Xcode 5.1 (potentially earlier)
IB, apparently, only allows multipliers to be set to integers or ratios, not floating point numbers. Here's a screen cap for more clarity
Note: if "First Item" and "Second Item" are flipped, the ratio is "2:1"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With