Swiftui Foundation: how to make pictures spread all over the screen

Time:2021-5-12

Suppose we have a picture that we want to spread all over the screen?

Set the background first

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack{
            CircleImage(imageName: "lilly")
                .frame(width:160,height:160)
                .padding(.top,89)
                .padding(.bottom,20)
     
        }
        .background(
            Image("lotus")
                .resizable()
                .scaledToFill()
              
        )
        
    }
}

The effect is not satisfactory, not spread out
Swiftui Foundation: how to make pictures spread all over the screen

Then fill the container full screen

We can use spacer () to support vstack

struct ContentView: View {
    var body: some View {
        VStack{
            CircleImage(imageName: "lilly")
                .frame(width:160,height:160)
                .padding(.top,89)
                .padding(.bottom,20)
            Spacer()
        }
        .background(
            Image("lotus")
                .resizable()
                .scaledToFill()
             
        )
        
    }
}

The effect is OK, but the bangs and the bottom have not been laid yet.

Swiftui Foundation: how to make pictures spread all over the screen

Use edgesigning safearea to spread the whole screen

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack{
            CircleImage(imageName: "lilly")
                .frame(width:160,height:160)
                .padding(.top,89)
                .padding(.bottom,20)
            Spacer()
        }
        .background(
            Image("lotus")
                .resizable()
                .scaledToFill()
                .edgesIgnoringSafeArea(.all)
        )
        
    }
}

The final effect

Swiftui Foundation: how to make pictures spread all over the screen

More swiftui tutorials and code focus columns

  • Please pay attention to my column icloudend, swiftui tutorial and source code

Recommended Today

Looking for frustration 1.0

I believe you have a basic understanding of trust in yesterday’s article. Today we will give a complete introduction to trust. Why choose rust It’s a language that gives everyone the ability to build reliable and efficient software. You can’t write unsafe code here (unsafe block is not in the scope of discussion). Most of […]