Search code examples
autolayoutuilabelconstraintsline-breaks

UILabel with linebreak and auto layout


So I've been having this issue for a while. I have a UILabel which has a constraint for the auto layout. However the label text is too long so parts of the text appears off the screen.

I've tried setting the number of line both within the storyboard settings and also thru this code:

label.numberOfLines = 0;

The code works like a charm until I add a constraint for the label.

Any ideas on how I could fix this?


Solution

  • Add this code..

    _lable.numberOfLines=0;
    _lable.preferredMaxLayoutWidth = 300.0; //Add width
    

    UILabel documentation