Juan Garcia
Juan Garcia

Reputation: 97

Center two UIViews of different size horizontally

I have the following wireframe:

enter image description here

I need to add the "Don't have an account yet? Sign Up.". To do this I'll have two different UILabels, one with "Don't have an account yet?" and another with "Sign Up" so I can style them separately.

My problem is that I don't know how to center to the Superview two different labels that have different size and my grow if it's localized to a language where they take more space than english...

So the questions would be: "How do I center two UILabels with different width related to it's superview?"

Thanks a lot!

Upvotes: 5

Views: 380

Answers (2)

Bhavin Bhadani
Bhavin Bhadani

Reputation: 22374

Here is the steps:

  1. Take a view that contains both of your labels and make centerx to it.
  2. Pinned label 1 with all sides with greater then equal width constraint
  3. and follow step 2 for label2.

Here is the visual presentation of it...

enter image description here

Upvotes: 6

ChikabuZ
ChikabuZ

Reputation: 10205

You should put them into container UIView make it flexible width (for ex. >= 10) and center it.

Upvotes: 6

Related Questions