Noah Iarrobino
Noah Iarrobino

Reputation: 1543

Pin image to top of a view in SwiftUI

I am fairly new to SwiftUI and am building a Widget, but I cannot figure out how to pin an image to the top of a view, this is what I've tried but it just defaults to the center of the widget, how can I pin it to the top?

var body: some View {
            
       Image("nav_logo")
         .edgesIgnoringSafeArea(.top)
}

Upvotes: 1

Views: 1029

Answers (1)

aheze
aheze

Reputation: 30318

Use a VStack and Spacer.

var body: some View {
    VStack {     
        Image("nav_logo")
            .edgesIgnoringSafeArea(.top)

        Spacer() /// will push the image up
    }
}

Upvotes: 1

Related Questions