在文本中添加无限行(SwiftUI) [英] Adding unlimited lines in a Text (SwiftUI)
问题描述
只需弄清楚如何在Text
中实现多行文本即可.似乎Text
具有与UILabel
相同的默认设置(一行),但是我找不到满足此条件的任何函数.
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), but I can't find any function which meets this criteria.
struct ContentView : View {
var body: some View {
VStack(alignment: .leading, spacing: 10) {
HStack {
Text("Avocado Toast").font(.system(size: 24))
}
// This Text does cut, and I wonder how I can achieve multiple rows
Text("Ingredients: Avocado, Almond Butter, Bread")
.font(.system(size: 20))
}
}
}
编辑
.lineLimit(X)
,成功了.但是,例如,可以不设置特定的数量.只有0?
Edit
.lineLimit(X)
, did the trick. But is it possible to not set a specific amount, for instance. With just a 0?
推荐答案
使用.lineLimit()
限制文本行数.它使用一个可选的Int(Int?
)作为参数,并且.lineLimit(nil)
允许无限制的行.
Use .lineLimit()
to limit the amount of lines of text. It takes an optional Int (Int?
) as an argument, and .lineLimit(nil)
allows unlimited lines.
编辑:自SwiftUI Beta 5起,Text
的默认行数限制为nil
,因此默认情况下,Text
中的文本将自动换行.
Edit: As of SwiftUI Beta 5, Text
has a default line limit of nil
, so text in Text
will wrap by default.
这篇关于在文本中添加无限行(SwiftUI)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!