rookie IOS developer here migrating from an Android code base.
In android if we wanted a container that automatically adjusted its height based on its internal contents, we would just do something like the following
<LinearLayout
android:orientation="vertical"
android:layout_width="500dp"
android:layout_height="wrap_content">
...
</LinearLayout>
How is this achieved in autolayout through the storyboard? How can I make a stackview
or containerview
's width or height to be wrap_content
?
You can accomplish the same on ios by using UIStackView (Verticl/Horizontal) or UIScrollview
let me explain the whole process in scrollview
1- drag a scrollview to your view controller in storyboard file/Xib
2- give the storyboard leading , trailing , top , bottom constraints to the main view
3- drag a UIView (contentView) inside the scrollView and hook it's leading , trailing , top , bottom constraints to the scrollview
4- control-drag from the contentView to the mainView and select Equal-widths constraint
until this step you have a scrollview that is ready to be wrapped according to the inner size of it's components
5- drag a UILabel and hook it's leading , trailing , top , bottom constraints to the contentView
in runtime change the content of that label and the scrollview will wrap according to the label content
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