I have this text below that is too long to fit on the screen when it runs. How can I make this 2 lines rather than one?
myLabel.text = "The weather today is going to be partly cloudy with a chance of rain"
I have this text below that is too long to fit on the screen when it runs. How can I make this 2 lines rather than one?
myLabel.text = "The weather today is going to be partly cloudy with a chance of rain"
#1
Set the number of lines:
myLabel.numberOfLines = 2 //set to 0 if you want it to automatically decide based on how many line breaks you add in step 2
#2
Add line breaks in your text using \n
or \r
:
myLabel.text = "The weather today is going to\nbe partly cloudy with a chance of rain"
Hope that helps :)
Edit
You should have clarified that you are using a SKLabelNode
rather than a normal UILabel
. Here is what you could do since SKLabelNode
s do not support multiple lines.
edit/update:
**For iOS 11 or later you can set numberOfLines, lineBreakMode, and preferredMaxLayoutWidth properties. attributedText is supported as well **
Original answer
You can create your own method to display multi line text as follow: