Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

automatic multiline label swift

Tags:

xcode

swift

label

I have a label and I insert text in it. The label has a size but my problem is this:

when I insert text in label if the text is longer than label'size appears "...." in the label; for example:

if complete string that I want insert in the label is this : "hello world how are you?"

in the label I see this "hello world..."

I would like that label wraps automatically.

For this reason I did this but it doesn't work:

label!.textAlignment = NSTextAlignment.Center;
label!.numberOfLines = 0;
label!.font = UIFont.systemFontOfSize(16.0);
label!.text = "hello world how are you?"

Where do I wrong?

like image 679
Alex Avatar asked Dec 03 '22 16:12

Alex


1 Answers

  label.lineBreakMode = .byWordWrapping
  label.numberOfLines = 0;

or adjust the font size as below to fit the whole string

label.adjustsFontSizeToFitWidth = true
like image 179
good4pc Avatar answered Jan 03 '23 10:01

good4pc