In storyboard
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 ?
In storyboard
This is result...
I want to show same label width + truncate tail lable.
Best result is like this...
How do I set the constraints ?
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)
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:
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)
Notice the constraint is now automatically labelled as "Proportional Width" and not "Equal Width"
Pin each label to the respective side of the cell.
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.
[
You now should be set to go. If you inspect each label it will have four constraints thus:
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.
Give Equal width to labels. Pin top, bottom, left, right constraints to labels.
Check Gif Image for more clarification