我正在尝试设置一个NavigationButton
显示图像,而不仅仅是蓝色按钮。
目前,我正在显示一个水平的,Scrollview
,由图像组成。
这些图像应该导致另一个视图,该视图将呈现在rootView
.
然而,当我将这些图像包裹在NavigationButton
,这些图像结果只是蓝色,而不是显示预期的原始图像。
CategoryRow 组件 (ScrollView
)
ScrollView(showsHorizontalIndicator: false) {
HStack(alignment: .top, spacing: 0) {
ForEach(categorizeCountry()) { place in
NavigationButton(destination: PlaceDetail(place: place)) {
Image(place.imageName)
.resizable()
.clipShape(Rectangle())
.frame(width: 225, height: 150)
.cornerRadius(8)
.padding(.leading, 2)
.padding(.trailing, 2)
}
}
}
}
ContentView(呈现 CategoryRow 的位置)
var body: some View {
NavigationView {
List {
FeaturedCard(places: fiveRandomPlaces)
CategoryRow(label: "Australia")
CategoryRow(label: "Japan")
CategoryRow(label: "Singapore")
CategoryRow(label: "Indonesia")
ForEach(store.places) { place in
PlaceCell(place: place)
}
}
.navigationBarTitle(Text("Been There"))
.navigationBarItems(trailing: Button(action: sortPlaces) {
Text("Sort")
})
.listStyle(.grouped)
}
}
我希望图像能够像按钮一样工作(确实如此),但仍然显示原始图像,而不是全蓝色。
预期结果和实际结果的图片如下: