Line Breaks and Number of Lines in Swift Label (Programmatically)

tika picture tika · Jan 4, 2015 · Viewed 80.9k times · Source

By selecting a Label in a StoryBoard, I can select Line Break to be Word Wrap and change number of lines to be more than 1. How can I do that Programmatically in Swift?enter image description here

Answer

rakeshbs picture rakeshbs · Jan 4, 2015

You can do this to set it programmatically

 label.lineBreakMode = NSLineBreakMode.ByWordWrapping
 label.numberOfLines = 3

Swift 3/4

label.lineBreakMode = .byWordWrapping
label.numberOfLines = 3