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

后端 未结 3 1615
再見小時候
再見小時候 2021-02-01 02:11

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 Programma

3条回答
  •  耶瑟儿~
    2021-02-01 02:40

    If you want the label to have multiple lines, do this:

    var myLabel:UILabel = UILabel(frame: CGRectMake(7, 200, 370, 100))
    myLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping
    myLabel.numberOfLines = 0                      //'0' means infinite number of lines
    

    Do remember to increase the height in "CGRectMake(7, 200, 370, 100)"         <-- This
    Otherwise the label won't be able to take the multiple lines of text.

提交回复
热议问题