-1

enter image description here

In storyboard

enter image description here

This is result...

I want to show same label width + truncate tail lable.

Best result is like this...


Label1Label1Label1Label1La...(space)Label2Label2Label2Label2La...

How do I set the constraints ?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
AKillUea
  • 145
  • 1
  • 1
  • 9
  • 1
    http://stackoverflow.com/questions/29620409/need-assistance-setting-two-buttons-of-equal-width-side-by-side-autolayout/29620794#29620794 – Bhavin Bhadani Apr 29 '16 at 07:34
  • Use like ..http://stackoverflow.com/questions/28148843/ios-autolayout-two-buttons-of-equal-width-side-by-side/36597095#36597095 – Vvk Apr 29 '16 at 07:36

3 Answers3

2

select 2 Label and give equal widths constraints. give following constraints forr all buttons:

1.Height constraint.

2.Leading Constraint.

2.Bottom Constrain.

4.Equal Width Constraint

5.Trailing Constraint(if necessary)

enter image description here

Mr. Bond
  • 427
  • 1
  • 4
  • 18
2

Graceful Proportional Scaling

These days I recommend proportional constraints to achieve what you want.

Add the labels to your cell prototype and shape and align them as you want, in a storyboard scene that is 600x600 I have made the cell prototype full width (600), the labels I have made 240 wide. Then I have positioned them with the green label at x==0 and the grey label at x==360. Both my labels I have centered vertically within the cell.

Time for constraints. One approach would be to size the green label and then have the grey label mimic it. I eschew that approach and make each label's size proportionally dependent on it's superview. To do this set each labels width to be equal to that of it's superview:

Equal height and centered vertically

Then select the equal width constraint in the inspector and adjust the multiplier (in my case the multiplier needs to be 0.4 - 240/600 = 0.4)

change the equal width to a proportional width

Notice the constraint is now automatically labelled as "Proportional Width" and not "Equal Width"

Pin each label to the respective side of the cell.

Pinning a label

Now you could add constraints to specifically define the height of the labels but instead, as I know I have sized the labels correctly in the storyboard (240 wide by 21 high) I will create an Aspect Ratio constraint.

[Aspect Ratio Constraint4]

You now should be set to go. If you inspect each label it will have four constraints thus:

Final Constraints

As a bonus your cell will scale beautifully on different screen format sizes AND if you ever wish to change one of the labels there is no dependency between the labels, so changing one label will not break the other label.

Damo
  • 12,840
  • 3
  • 51
  • 62
1

Give Equal width to labels. Pin top, bottom, left, right constraints to labels.

Check Gif Image for more clarification

enter image description here

Sheereen S
  • 1,292
  • 10
  • 18