import SwiftUI
struct FrameModifierDemo: View {
var body: some View {
VStack(spacing: 20) {
Rectangle()
.fill(Color.blue)
.frame(width: 150, height: 100)
Text("Blue Box")
.font(.headline)
.foregroundColor(.black)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.white)
.edgesIgnoringSafeArea(.all)
}
}
struct FrameModifierDemo_Previews: PreviewProvider {
static var previews: some View {
FrameModifierDemo()
}
}We use a Rectangle view and fill it with blue color. The frame modifier sets the rectangle's width to 150 points and height to 100 points. The VStack arranges the rectangle and the label vertically with some spacing. The whole stack is centered by setting its frame to take the full available space with maxWidth and maxHeight set to infinity. This centers the content both horizontally and vertically. The label below the rectangle uses a headline font and black color for good contrast.