Set an image as the background in SwiftUI

Hello there!
I would like to set an image as the background of my project in SwiftUI, but I have no idea how it is done.
Could anyone help me to figure out this?

I am using Swift Playgrounds and SwiftUI framework.

Answered by Claude31 in 711052022

Use a ZStack:

For a color,

    var body: some View {
        ZStack { 
                Color.purple
                    .ignoresSafeArea()

For an image:

    var body: some View {
        ZStack { 
            Image("my image")
                    .ignoresSafeArea()
Accepted Answer

Use a ZStack:

For a color,

    var body: some View {
        ZStack { 
                Color.purple
                    .ignoresSafeArea()

For an image:

    var body: some View {
        ZStack { 
            Image("my image")
                    .ignoresSafeArea()
Set an image as the background in SwiftUI
 
 
Q