Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: UILabel how to show all text

I am very new to Swift and I don't know how to make my UILabel show all text.

Here is how my label looks like in my storyboard:enter image description here

As you see, part of the text is omitted. I can show all the text by dragging the UILabel to resize. However, during the runtime, if the text is set dynamically, how can I resize the label so that it can show more all of the text?

I tried UILabel.sizeToFit() but that doesn't seem to change anything.

like image 551
Guangyu Wang Avatar asked Dec 04 '22 03:12

Guangyu Wang


2 Answers

you can do this by setting numberOfLines to 0

Example

 myLabel.text = "whatever"
 myLabel.numberOfLines = 0
 myLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping

And you have so set frame according to it

Refer : to this link

like image 119
iDhaval Avatar answered Jan 04 '23 02:01

iDhaval


YourUILabel.sizeToFit() is right but that is not all of it..

You need to set the number of lines and the kind of line break before calling .sizeToFit()..

YourUILabel.numberOfLines equal to 0 for unlimited number of lines...

YourUILabel.lineBreakMode equal to NSLineBreakMode dot(.) ByWordWrapping for example..

like image 33
0yeoj Avatar answered Jan 04 '23 02:01

0yeoj