There is a label in the storyboard into which text of various lengths is inserted.

@IBOutlet weak var textLabel: UILabel! textLabel.numberOfLines = 0 textLabel.text = "длинный текст" textLabel.sizeToFit() 

The problem is that this text is cut if it is long. How to avoid it?

textLabel.sizeToFit() does not help.

  • Is sizeToFit () actually called EVERY time after a new text is set? or just once at the beginning? - Andrey Chernukha
  • every time you change - Eugene Strelnikov

2 answers 2

I had a similar task. I give the code that works in my application:

 textLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping textLabel.numberOfLines = 0 textLabel.text = "длинный текст" 

    Add a line to update new sizes.

     textLabel.setNeedsDisplay() 
    • Try to write more detailed answers. Explain what is the basis of your statement? - Nicolas Chabanovsky