【发布时间】:2020-04-27 16:01:32
【问题描述】:
我希望在 Swift UI 中创建一个全屏可滚动视图。在将视图放入滚动视图和垂直堆栈后,我在让视图全屏显示时遇到问题?有什么建议?
这就是我的代码的样子
struct ContentView : View {
var body: some View {
//var posts = [Post(postColor: .red), Post(postColor: .blue), Post(postColor: .green)]
ScrollView(.vertical, showsIndicators: false) {
VStack {
Post(postColor: .red)
Post(postColor: .blue)
Post(postColor: .green)
}
}
}
}
struct Post : View {
var postColor : Color
var body : some View {
VStack(alignment: .leading) {
HStack {
Text("Name")
.font(.title)
.fontWeight(.heavy)
Spacer()
}
Text("@Username")
.lineLimit(nil)
.font(.body)
Spacer()
}.background(postColor)
}
}
图片 This is the output I have after embedding in a scrollview.
【问题讨论】:
标签: ios xcode scrollview ios-simulator swiftui