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

后端 未结 3 1576
再見小時候
再見小時候 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:35

    Note with Swift 3 you need to use updated method byWordWrapping

    productNameLabel.lineBreakMode = .byWordWrapping
    productNameLabel.numberOfLines = 1
    


    Or for adding Ellipsis at the end use byTruncatingTail

    productNameLabel.lineBreakMode = .byTruncatingTail
    productNameLabel.numberOfLines = 1
    

提交回复
热议问题