[SwiftUI] I tried to find out how it changes for each specified location of background

In SwiftUI, the background was not filled as I expected, so I tried to find out where and how it would be filled.

Code and View

struct ContentView: View {
        
    var body: some View {
        VStack {
            Spacer()
            Text("Hello world!")
                .foregroundColor(Color.white)
                .background(Color.green)
                .frame(maxWidth: .infinity, minHeight: 50)
                .background(Color.blue)
                .padding()
                .background(Color.orange)
            Spacer()
        }.frame(width: 320, height: 100)
    }
    
}

// Present the view controller in the Live View window
PlaygroundPage.current.liveView = UIHostingController(rootView: ContentView())

スクリーンショット 2020-10-06 11.30.38.png

Commentary

--If you specify background before frame, it will be filled in the range of the text (green). --If there is a background after the frame and a padding after the background, it is filled inside by the padding (blue). --If you specify background after padding, padding is also filled with the ignored area (orange).

By paying attention to the position of background in this way, it seems that you can fill as expected.

Recommended Posts

[SwiftUI] I tried to find out how it changes for each specified location of background
[Ruby] How to find the sum of each digit
I tried to find out what changed in Java 9
I tried to make it possible to set the delay for the UDP client of Android by myself
[Rails] How to change the page title of the browser for each page
How to find out the Java version of a compiled class file
Since the docker-desktop preview for m1 came out, I tried to face it with my macbook pro 15inch
Ruby: I tried to find out where Nokogiri goes to see the encoding himself
How to display the amount of disk used by Docker container for each container
I made a sample of how to write delegate in SwiftUI 2.0 using MapKit
How to find the cause of the Ruby error
How to find OSS trends for web development
I tried to chew C # (basic of encapsulation)
How to specify index of JavaScript for statement
I tried to investigate the mechanism of Emscripten by using it with the Sudoku solver
First AWS Lambda (I tried to see what kind of environment it works in)