0

I am creating a view within IB and and attempting to have 3 UILabels evenly space horizontally across the view. I came across this on SO, https://stackoverflow.com/a/30249550/4597666. I have three UILabels, each have the height and width constrained. Here is what the IB looks like:

enter image description here

I constrained each centered horizontally, and the first UILabel I have the multiplier 3:1, second, 3:3, third 3:5 like the post states.

enter image description hereenter image description hereenter image description here

When I run on my emulator, I don't get the result that I was expecting. It appears all three UILabels are centered horizontally, and the first and third are not offset.

enter image description here

Is there another setting that I'm missing, or another way to properly space the views evenly?

Community
  • 1
  • 1
Mike Walker
  • 2,944
  • 8
  • 30
  • 62
  • Have you checked the first and second are definitely behind the 3rd in the centre? Or are they potentially offscreen elsewhere? – myles Sep 17 '15 at 17:10
  • Thanks for the comment. I went and checked more into it, and the ratios were actually backwards. Instead of doing 3:1 I needed 1:3. Likewise with 3:5 I needed 5:3. – Mike Walker Sep 17 '15 at 18:02
  • Just a heads up, if you do it that way, I'm pretty sure there will be even spacing between the middle view and the outer 2 views, but this gap will not be equal to the gap between the outer views and the edges of the screen. If you want equal gaps between screen edges and all views you may need a different method. – myles Sep 17 '15 at 18:06

1 Answers1

0

you need to make only one change.

Constraint you set is 3.CenterX to Superview.CenterX all you need to do is interchange the value so that you constraint should look like in below image.

enter image description here enter image description here enter image description here

Alternative solution. If you want to set constraints currently you have set then change the ratio from "3:5" to "5:3" and similar for all the labels.

enter image description here

Result:

enter image description here

enter image description here Hope it helps you solving your problem.

Dhaivat Vyas
  • 2,926
  • 1
  • 16
  • 26