In SwiftUI, the background was not filled as I expected, so I tried to find out where and how it would be filled.
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())

--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