2

Trying to set an image as a background for my view in SwiftUI. Using Xcode 12 beta and iOS 14.

struct ContentView: View {
var body: some View {
    ZStack {
        Image("background")
            .resizable()
            .scaledToFill()
            .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height, alignment: .center)
            .clipped()
    }
}

}

Output

enter image description here

4

1 回答 1

2

The following should be enough (tested with Xcode 11.4 / iOS 13.4)

var body: some View {
    ZStack {
        Image("background")
            .resizable()
            .scaledToFill()
            .edgesIgnoringSafeArea(.all)
    }
}
于 2020-07-17T06:47:28.630 回答