简体   繁体   中英

How do I center an Image view in pdf format with SwiftUI?

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:

在此处输入图像描述

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?

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

演示

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

Tested with Xcode 13.3 / iOS 15.4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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