ios - 是否可以更改 NavigationButton 以显示图像而不是蓝色?

标签 ios swift swiftui

我正在尝试设置一个 NavigationButton 来显示一个图像,而不仅仅是一个蓝色按钮。

目前,我正在显示一个水平的 Scrollview,它由图像组成。

这些图像应该指向另一个 View ,该 View 将呈现在 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)
        }
    }

我希望图像能像按钮一样工作(确实如此),但仍显示原始图像,而不是全蓝色。

预期结果和实际结果的图像如下:

Expected Result

Actual Result

最佳答案

尝试改变渲染模式

Image(place.imageName)
    .renderingMode(.original)

关于ios - 是否可以更改 NavigationButton 以显示图像而不是蓝色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56541718/

相关文章:

linux - Swift 字符串 hasSuffix 错误

ios - EZAudio 无法工作 : Thread1 EXC_BAD_ACCESS while creating EZRecorder instance

swiftui - watchOS 上使用 SwiftUI 的意外(自动)导航

iphone - cellForRowAtIndexPath 返回 nil

ios - 禁用/隐藏一个 View Controller 的 Root View Controller

ios - 快速更改多种颜色的 UISlider 轨道颜色?

ios - 成功登录后导航未激活

ios - 如何为用户的语言环境设置当前日期的格式?

ios - 快速返回另一页后, TableView 单元格正在复制

checkbox - 如何在 SwiftUI 中预选复选框