所以我正在试用SwiftUI,不幸的是,它仍然存在一些问题,但我不知道它是站在我这边还是有问题。我正在尝试在ForEach旁边使用SegmentedControl,它可以显示图像,但SegmentedControl的标签已经消失了。
这是我的ContentView:
struct ContentView : View {
@State var filter = 0
var body: some View {
NavigationView {
SegmentedControl(selection: $filter) {
Text("Tag1").tag(0)
Text("Tag2").tag(1)
}.padding(.bottom)
ForEach(1...3) { spot in
ZStack {
Image("placeholder")
.frame(height: 200)
.clipped()
Text("Swift")
.font(.largeTitle)
.foregroundColor(.white)
}.padding(.bottom, -8)
}.navigationBarTitle(Text("Explore"))
}
}
}我不明白为什么它会坏掉,但它确实坏了。是我用错了,还是这只是个bug?

发布于 2019-06-17 19:22:23
你的SegmentedControl被拉长了,原因是你的形象。SegmentedControl的宽度被拉伸到图像的大小,而您正在为图像设置自定义边框,而没有使其可调整大小。这就是为什么您的标签是越界的。只需将.resizable()添加到您的图像,这将固定您的图像的大小,您的标签也会显示出来:
Image("placeholder")
.resizable()
.frame(height: 200)
.clipped()https://stackoverflow.com/questions/56589871
复制相似问题