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:
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.
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
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 to0
for unlimited number of lines...
YourUILabel.lineBreakMode
equal toNSLineBreakMode
dot(.)ByWordWrapping
for example..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With