Home > Software engineering >  How do I center an Image view in pdf format with SwiftUI?
How do I center an Image view in pdf format with SwiftUI?

Time:05-15

I have a vector (converted to Pdf) that I want to use as my background for my app. However, the Image is aligned all the way to the left as you'd expect when using GeometryReader. Perhaps it's not even GeometryReader doing this! Here is a photo:

enter image description here

As you can see the blue box (not sure what actual name of it is) shows only the very leftmost of my image is shown on my devices. Is there a way to control where this position is? For example, having the device in the center or all the way on the right? So that I can choose which part of the image I want to be sure shows up on screen?

CodePudding user response:

A possible solution is to move image inside full-area container, like

demo

    GeometryReader { _ in
        Color.clear.overlay(    // << here !!
            Image("picture")
                .resizable()
                .scaledToFill()
                .ignoresSafeArea()
        )
    }

Tested with Xcode 13.3 / iOS 15.4

  • Related