Line Breaks and Number of Lines in Swift Label (Programmatically)
问题 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? 回答1: You can do this to set it programmatically label.lineBreakMode = NSLineBreakMode.ByWordWrapping label.numberOfLines = 3 Swift 3/4 label.lineBreakMode = .byWordWrapping label.numberOfLines = 3 回答2: If you want the label to have multiple lines, do this: var myLabel:UILabel = UILabel(frame: CGRectMake(7, 200, 370, 100))