Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI:- Image won't show on the View

Tags:

swiftui

I am playing around with SwiftUI and I am stuck on this View. everything is working fine but this little bug is very frustrating.I am trying to display the images as a vertical view and it won't show on the view . I know the Images are loaded but the view is not showing it . Its covered in blue color.

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"))
    }
}

}

I tried to put the NavigationView under the ZStack but it did not work.I have no Idea what I did wrong on the code. No error message on the debugger. just doesn't show the images.

like image 381
Asge Yohannes Avatar asked Jul 10 '19 03:07

Asge Yohannes


1 Answers

The NavigationLink applies a button style to the objects it holds. Button does the same. To remove the blue color, add the buttonStyle modifier:

NavigationLink(destination: ...) {
    ...
}
.buttonStyle(PlainButtonStyle())

You can create and apply your own button style as well.

like image 102
zh. Avatar answered Dec 28 '22 02:12

zh.