我想做一个水平叠加的图像。不幸的是,我无法幻灯片看到完整的图像。
struct ContentView: View {
var body: some View {
NavigationView {
List {
ScrollView {
VStack{
Text("Images").font(.title)
HStack {
Image("hike")
Image("hike")
Image("hike")
Image("hike")
}
}
}.frame(height: 200)
}
}
}
}

发布于 2019-09-19 19:09:34
你的观点有几个问题。
你在你的内容周围有一个列表-它会造成问题,因为一个列表垂直滚动,而我假设你希望你的图像水平滚动。
其次,您可能不希望您的标题与图像滚动-它需要到滚动视图之外。
最后但并非最不重要的是,您需要使图像可调整大小,并设置它们的高宽比,以便缩小它们以适应所分配的空间。
试试这个:
struct ContentView: View {
var body: some View {
NavigationView {
VStack{
Text("Images").font(.title)
ScrollView(.horizontal) {
HStack {
Image("hike")
.resizable()
.aspectRatio(contentMode: .fit)
Image("hike")
.resizable()
.aspectRatio(contentMode: .fit)
Image("hike")
.resizable()
.aspectRatio(contentMode: .fit)
Image("hike")
.resizable()
.aspectRatio(contentMode: .fit)
} .frame(height: 200)
Spacer()
}
}
}
}
}https://stackoverflow.com/questions/58011772
复制相似问题