May Phyu
May Phyu

Reputation: 905

Auto Label Height in swift 3

I would like to adjust the height of label in my app.

enter image description here

I set Number of Lines: 0 in Attribute Inspector. I made Trailing, Leading and Top constraints.

I would like to get label height adjustment. Can anyone help me please?

Upvotes: 0

Views: 3047

Answers (2)

Nirav D
Nirav D

Reputation: 72410

What you can do is set that label's bottom to the director's name label also set the greater than equal to (>=) constraints for your label height, So it will looks like this.

enter image description here

Now set the constrains for the director's name label to leading, trailing and height with greater than equal to (>=). Now also set the Director heading label top to this director's name label. So you are having constrains for this label like this.

enter image description here

Now simply select the Director heading label and set the fixed width height leading and trailing, Don't forgot to set its top to Director's name label. So the final result give you like this.

enter image description here

Note: Don't forgot to set numberOfLines to 0 for both of your cast name label and director name label.

Upvotes: 3

Jigar Tarsariya
Jigar Tarsariya

Reputation: 3237

If you have given constraints to your label then you have to write it like,

 self.lblText.numberOfLines = 0
 self.lblText.lineBreakMode = .byWordWrapping
 self.lblText.sizeToFit()

This adjust your label based on your text string.

Upvotes: 2

Related Questions