0

So the main problem is showing in the picture itself. How can I make a double line horizontally label using my constraints, so I could show the entire text without cutting it?

enter image description here

Hamish
  • 78,605
  • 19
  • 187
  • 280
tomasfn
  • 26
  • 1
  • 5

2 Answers2

1

You can achieve that with two changes,

  1. Set the Lines field in attribute inspector to 0
  2. Do not specify a fixed height constraint for your UILabel.

Update:

In order to make the constraints to behave properly for a given UI element, you will have to have a minimum of 4 constraints on it.

  1. Constraint to define its X position
  2. Constraint to define its Y position
  3. Constraint to define the width of the element
  4. Constraint to define the height of the element

Since I do not have a clear picture of what your UI would look like, I'm giving a simple example. Assuming you have two labels one below the other and you want multi-line behavior for the second UILabel.

  1. Define your X position, add a leading edge constraint to the margin or the edge based on your requirement
  2. Define your Y position, add a vertical spacing constraint from your second label to the first label
  3. To define the width, add a trailing edge constraint to the trailing margin or the edge
  4. To define the height, add height >= 20 (or the number you need) constraint

And ensure you have the lines property to be 0.

R P
  • 1,173
  • 2
  • 11
  • 20
  • Thank you RP, did the 1st step but couldn't understand well the 2nd one. Because I think I don't have any fixed height, or didn't understand what you meant. The label has 2 constraints as I can see, a Center Y alignment constraint and Horizontal space contraint. I think is related to the first one. Here is a pic about I have https://i.imgur.com/wAYmdZG.png – tomasfn Feb 14 '16 at 22:27
  • Check out this SO question to understand further: http://stackoverflow.com/questions/12789013/ios-multi-line-uilabel-in-auto-layout?rq=1 – R P Feb 15 '16 at 01:12
0

You can do with on storyboard. Click it later look at bottom side Resolve >Auto Layout Issues and click update frames. i think auto do this.

Thanks

SwiftDeveloper
  • 7,244
  • 14
  • 56
  • 85