我正在尝试重现Apple教程(组成复杂接口),但我遇到了一个很奇怪的问题。我的CategoryItem视图显示为蓝框。

如果我删除包裹它的NavigationLink,则一切正常,但使用后者则无效。

struct CategoryRow: View {
    var categoryName: String
    var items: [Landmark]

    var body: some View {

        VStack(alignment: .leading) {
            Text(self.categoryName)
                .font(.headline)
                .padding(.leading, 15)
                .padding(.top, 5)

            ScrollView(.horizontal, showsIndicators: false) {
                HStack(alignment: .top, spacing: 0) {
                    ForEach(self.items) { landmark in
                        NavigationLink(
                            destination: LandmarkDetail(
                                landmark: landmark
                            )
                        ) {
                            CategoryItem(landmark: landmark)
                        }
                    }
                }
            }.frame(height: 185)
        }
    }
}

ios - SwiftUI View 以蓝色背景显示-LMLPHP

最佳答案

NavigationLink默认具有蓝色的重音颜色,只需在其上调用.accentColor(Color.clear)
或者,您可以尝试以下操作:

NavigationView {
    NavigationLink(destination: Text("Detail view here")) {
        Image("YourImage")
    }
    .buttonStyle(PlainButtonStyle())
}

https://www.hackingwithswift.com/quick-start/swiftui/how-to-disable-the-overlay-color-for-images-inside-button-and-navigationlink

关于ios - SwiftUI View 以蓝色背景显示,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58713872/

10-12 04:57