UILabel - Wordwrap text

前端 未结 4 1859
北海茫月
北海茫月 2020-12-22 17:48

Is there any way to have a label wordwrap text as needed? I have the line breaks set to word wrap and the label is tall enough for two lines, but it appears that it will on

相关标签:
4条回答
  • 2020-12-22 18:07

    Xcode 10, Swift 4

    Wrapping the Text for a label can also be done on Storyboard by selecting the Label, and using Attributes Inspector.

    Lines = 0 Linebreak = Word Wrap

    0 讨论(0)
  • 2020-12-22 18:20

    If you set numberOfLines to 0 (and the label to word wrap), the label will automatically wrap and use as many of lines as needed.

    If you're editing a UILabel in IB, you can enter multiple lines of text by pressing option+return to get a line break - return alone will finish editing.

    0 讨论(0)
  • 2020-12-22 18:22

    In Swift you would do it like this:

        label.lineBreakMode = NSLineBreakMode.ByWordWrapping
        label.numberOfLines = 0
    

    (Note that the way the lineBreakMode constant works is different to in ObjC)

    0 讨论(0)
  • 2020-12-22 18:25

    UILabel has a property lineBreakMode that you can set as per your requirement.

    0 讨论(0)
提交回复
热议问题