SwiftUI:- 图像不会显示在视图上

Asg*_*nes 6 swiftui

我正在玩 SwiftUI,但我被困在这个视图上。一切正常,但这个小错误非常令人沮丧。我试图将图像显示为垂直视图,但它不会显示在视图上。我知道图像已加载,但视图未显示。它被蓝色覆盖。

import SwiftUI 

struct PlanetHome : View {
var planets : [Planet]
var body : some View {
    NavigationView {
        ScrollView {
            ZStack {
                Color.black .edgesIgnoringSafeArea (.all)
                VStack (alignment: .center)
                {
                    ForEach (self.planets.identified(by: \.imageName))
                    {
                        planet in NavigationLink (destination: PlanetDetail(planets: planet))
                        {
                            PlanetsView (planets: planet)
                            .frame (width: 500, height: 500)
                            .padding (.vertical, 5)
                        }
                    }
                }
            }
        }
        .navigationBarTitle (Text("Planets"))
    }
}
Run Code Online (Sandbox Code Playgroud)

}

我试图将 NavigationView 放在 ZStack 下,但它不起作用。我不知道我在代码上做错了什么。调试器上没有错误消息。只是不显示图像。

zh.*_*zh. 9

NavigationLink按钮样式应用于它所持有的对象。Button做同样的事情。要移除蓝色,请添加buttonStyle修饰符:

NavigationLink(destination: ...) {
    ...
}
.buttonStyle(PlainButtonStyle())
Run Code Online (Sandbox Code Playgroud)

您也可以创建和应用自己的按钮样式。


Rad*_*ast -1

它被蓝色覆盖。

您可以使用 .foregroundColor(.YourColor) 将蓝色更改为您想要的任何颜色,或者只需在Assets.xcassets -> Pick Any Image -> Show the Attribute Inspector 中将“渲染为 默认”更改为“渲染为原始图像”

要解决其他问题,您应该包括PlanetsView因为当我放置 Image(systemName: "photo")而不是您的视图时,它会正确显示