SwiftUI HStack slider does not appear
我想水平堆叠图像。
不幸的是,我无法滑动以查看完整图像。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 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) } } } } |
您的观点有两个问题。
您的内容周围有一个列表-这会引起问题,因为列表垂直滚动,而我假设您希望图像水平滚动。
接下来的事情是,您可能不希望标题随图像一起滚动-它需要超出滚动视图的范围。
最后但并非最不重要的一点是,您需要调整图像的大小并设置其纵横比,以便将其缩小以适应分配的空间。
尝试一下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 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() } } } } } |