This is a result I need:
Width of labels are not fixed. They may be equal, first may be larger then second, and the second may be larger than first. I have found some solutions in other questions, but it does not satisfy me, because I do not want to add extra views and my widths are not fixed.
I made some research, and it is still impossible without extra view:-)
But the simplest way is:
1. constraints for wrapper:
2. constraints for embedded views:
3. The result is following:
Heres how to do it programmatically
let margins = view.safeAreaLayoutGuide
//Let x equal whatever you want your height to be
//Let y equal whatever you want your width to be
view1.topAnchor.constraint(equalTo: margins.topAnchor).isActive = true
view1.trailingAnchor.constraint(equalTo: margins.centerXAnchor).isActive = true
view1.widthAnchor.constraint(equalToConstant: X).isActive = true
view1.heightAnchor.constraint(equalToConstant: Y).isActive = true
view2.leadingAnchor.constraint(equalTo: margins.centerXAnchor, constant: 8).isActive = true
view2.topAnchor.constraint(equalTo: view2.topAnchor).isActive = true
view2.bottomAnchor.constraint(equalTo: view2.bottomAnchor).isActive = true
view2.widthAnchor.constraint(equalToConstant: X).isActive = true
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