简体   繁体   English

SwiftUI 视图以蓝色背景显示

[英]SwiftUI View displayed with blue background

I'm trying to reproduce the Apple tutorial(Composing Complex Interfaces) and I have a very weird problem.我正在尝试重现 Apple 教程(组合复杂接口),但我遇到了一个非常奇怪的问题。 My CategoryItem view is being displayed as a blue frame.我的CategoryItem视图显示为蓝框。

If I remove the NavigationLink which wraps it, everything works fine but with that one it doesn't.如果我删除了包裹它的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)
        }
    }
}

在此处输入图像描述

NavigationLink has a blue accent color by default, just call .accentColor(Color.clear) on it NavigationLink默认具有蓝色强调色,只需调用.accentColor(Color.clear)

Or you could try this:或者你可以试试这个:

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 https://www.hackingwithswift.com/quick-start/swiftui/how-to-disable-the-overlay-color-for-images-inside-button-and-navigationlink

renderingMode(.original) is what did it for me; renderingMode(.original)是为我做的; .accentColor(Color.clear) made the image invisible (my best explanation here is because it didn't have a transparency). .accentColor(Color.clear)使图像不可见(我最好的解释是因为它没有透明度)。

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

As the answer above mentioned, How to disable the overlay color for images inside Button and NavigationLink is a good write up as well.正如上面提到的答案, How to disable the overlay color for images inside Button and NavigationLink也是一个很好的文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM