我有以下内容,希望包装更长的文字
Text("Long label that needs to be able to wrap but isn't doing it yet.")
.font(.largeTitle)
.multilineTextAlignment(.center)
.lineLimit(0)
答案 0 :(得分:6)
结果证明,您可以将nil
传递到.lineLimit
,它将按需要进行Text()
换行。
Text("Long label that needs to be able to wrap but isn't doing it yet.")
.font(.largeTitle)
.multilineTextAlignment(.center)
.lineLimit(nil)
答案 1 :(得分:1)
我刚刚在最新的XCode 11 beta 7 beta中对此进行了测试。我需要指定一个非零行数限制,并且还使用padding
修饰符来获得多行文本
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.")
.font(.subheadline)
.multilineTextAlignment(.center)
.lineLimit(3)
.padding()