这是我想要做的最小可重现示例。
我有一个段落数组。
var notes = [
"One line paragraph",
"This is a small paragraph. This is a small paragraph. This is a small paragraph. This is a small paragraph.",
"This is a big paragraph. This is a big paragraph. This is a big paragraph. This is a big paragraph. This is a big paragraph. This is a big paragraph. This is a big paragraph. This is a big paragraph. This is a big paragraph. This is a big paragraph. This is a big paragraph."
]
这是我想要展示的方式:
![输入图片描述](https://istack.dev59.com/5i5W8.webp)
struct ContentView: View {
var notes = [
"One line paragraph",
"This is a small paragraph. This is a small paragraph. This is a small paragraph. This is a small paragraph.",
"This is a big paragraph. This is a big paragraph. This is a big paragraph. This is a big paragraph. This is a big paragraph. This is a big paragraph. This is a big paragraph. This is a big paragraph. This is a big paragraph. This is a big paragraph. This is a big paragraph."
]
var body: some View {
VStack(alignment: .leading) {
ForEach(self.notes, id: \.self) {note in
HStack {
Capsule()
.fill(Color.blue)
.frame(width: 4.5)
Text(note)
.lineLimit(nil)
}
.padding()
}
}
}
}
这是我得到的输出:
![enter image description here](https://istack.dev59.com/Hdy0t.webp)
ForEach
之后添加一个Spacer()
到VStack
底部,但输出仍然相同。我想知道的是如何将这些蓝色竖条的高度更改为它们各自段落的高度,就像第一个屏幕截图中的那样。