I am trying to understand the basic of dynamic layout using the intrinsic content size. As attached in the image, i have two UILabel's in horizontal which will be my default layout. How do make the layout constraints so that
You can add two labels to stackView and if the sum of intrinsicContentSize of and check with the UIScreen.main.bounds.width
minus the margins of left and right of stackView.
if (label1.intrinsicContentSize.width + label2.intrinsicContentSize.width) > (UIScreen.main.bounds.width - 48/* 48 is the left and right margins*/) {
stackView.axis = .vertical
}else {
stackView.axis = .horizontal
}
Remember to set the numberOfLines of labels to 0.
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