Search code examples
iosxcodeautolayout

How to center 2 labels horizontally side by side in XCode 6?


This is a result I need:

enter image description here

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.


Solution

  • I made some research, and it is still impossible without extra view:-)

    But the simplest way is:

    1. constraints for wrapper:

    enter image description here

    2. constraints for embedded views:

    enter image description here enter image description here

    3. The result is following:

    enter image description here

    enter image description here