Multiline label in UIStackView

后端 未结 21 2918
有刺的猬
有刺的猬 2020-12-02 04:30

When putting multiline label (with linebreak set to Word Wrap) into a stack view, the label immediately loses the linebreak and displays the label text in one line instead.<

21条回答
  •  孤城傲影
    2020-12-02 05:09

    The correct answer is here:
    https://stackoverflow.com/a/43110590/566360


    1. Embed the UILabel inside a UIView (Editor -> Embed In -> View)
    2. Use constraints to fit the UILabel to the UIView (for example, trailing space, top space, and leading space to superview constraints)

    The UIStackView will stretch out the UIView to fit properly, and the UIView will constrain the UILabel to multiple lines.

提交回复
热议问题