Since List doesn't look like its configurable to remove the row dividers at the moment, I'm using a ScrollView with a VStack inside it to create a vertical layout of text elements. Example below:
ScrollView {
VStack {
// ...
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer mattis ullamcorper tortor, nec finibus sapien imperdiet non. Duis tristique eros eget ex consectetur laoreet.")
.lineLimit(0)
}.frame(width: UIScreen.main.bounds.width)
}
Run Code Online (Sandbox Code Playgroud)
The resulting Text rendered is truncated single-line. Outside of a ScrollView it renders as multi-line. How would I achieve this inside a ScrollView other than explicitly setting a height for the Text frame ?
And*_*era 35
在Xcode 11 GM中:
对于Text嵌套在滚动视图中的堆栈中的任何视图,请使用.fixedSize(horizontal: false, vertical: true)解决方法:
ScrollView {
VStack {
Text(someString)
.fixedSize(horizontal: false, vertical: true)
}
}
Run Code Online (Sandbox Code Playgroud)
如果有多个多行文本,这也适用:
ScrollView {
VStack {
Text(someString)
.fixedSize(horizontal: false, vertical: true)
Text(anotherLongString)
.fixedSize(horizontal: false, vertical: true)
}
}
Run Code Online (Sandbox Code Playgroud)
如果堆栈的内容是动态的,则可以使用相同的解决方案:
ScrollView {
VStack {
// Place a single empty / "" at the top of your stack.
// It will consume no vertical space.
Text("")
.fixedSize(horizontal: false, vertical: true)
ForEach(someArray) { someString in
Text(someString)
.fixedSize(horizontal: false, vertical: true)
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 6
您可以强制视图填充其理想大小,例如在垂直 ScrollView 中:
ScrollView {
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer mattis ullamcorper tortor, nec finibus sapien imperdiet non. Duis tristique eros eget ex consectetur laoreet.")
.fixedSize(horizontal: false, vertical: true)
}
Run Code Online (Sandbox Code Playgroud)
对我来说感觉比修改框架好一点。
| 归档时间: |
|
| 查看次数: |
2160 次 |
| 最近记录: |