Adding unlimited lines in a Text (SwiftUI)

后端 未结 5 561
轮回少年
轮回少年 2020-12-06 04:53

Just figuring out how I can achieve multiple lines of text in a Text. It seems like the Text has the same default as UILabel (one line

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-06 05:29

    For wrapping Text in a Form .lineLimit(Int.max) did not work for me. It seems there needs to be some width for it to know when to wrap. I believe the official way is with .fixedSize:

    Text(message)
        .fixedSize(horizontal: false, vertical: true)
    

    The documentation states:

    This example shows the effect of fixedSize(horizontal:vertical:) on a text view that is wider than its parent, preserving the ideal, untruncated width of the text view.

提交回复
热议问题