2

I am setting constraints for 4 UILabels but its not working properly in iphone 5s and it's showing properly in 6 and 6 plus. How to set proper constraints?

enter image description here

its going right side in iphone 5s.

enter image description here

First label, I have set x position and then space between labels. Then I have set the fourth label <= from the trailing space. But not getting proper result.

Quentin Hayot
  • 7,786
  • 6
  • 45
  • 62

2 Answers2

1

Since your goal seems to be to display a single line of text with some links, you'd probably be better off using a single view for all the text. There are some third party substitutes for UILabel that support links such as Nimbus and TTTAttributedLabel. Or, you can configure a UITextView instance to work like a label (turn off scrolling and editing), and you can enable hyperlinks.

Using a single view that can properly handle hyperlinks should simplify your code and eliminate your constraints issue while ensuring that the text is properly layed out. For example, if the text needs to wrap to the next line, it's going to be a lot easier to accomplish that with a single view.

Massimo Polimeni's answer pretty well covers the answer to your stated question: if you want to position several labels so that their text lines up, use the Baselines constraint between the labels.

Caleb
  • 124,013
  • 19
  • 183
  • 272
0

Select all your labels and then add the Vertical centers constraint:

So now your labels should be align:

Obviously, add x position or margin contraints at only one label for maintain the alignment.

Let me know if this fix your problem :)


EDIT 1: as Caleb says, my suggestion works only if the labels as the same font size. If not you should use just baseline constraint.

Massimo Polimeni
  • 4,826
  • 4
  • 27
  • 54
  • 1
    The *Baselines* constraint would be a better choice than *Vertical Centers* for labels, just in case the labels happen to have different font sizes. – Caleb May 21 '15 at 15:02
  • Sure, I suggest this because the fonts seem to be the same. But it's better update my answer, thx – Massimo Polimeni May 21 '15 at 15:07
  • yes its working ,i i have button and lable then its not working –  May 22 '15 at 07:16
  • For button + labels use the Vertical Centers constraint; if you need to align button + labels with different font size you should embedded all your objects in a view and set for all Vertical Center in Container :) – Massimo Polimeni May 22 '15 at 08:26