SwiftUI 为我们提供了五个常用的内置形状:矩形、圆角矩形、圆形、椭圆和胶囊。下面我们通过简单的demo来直观看一下
五个常用的内置形状

五个常用的内置形状

ZStack应用基础形状

图像个性化形状
五个常用的内置形状代码
struct ShapeBox: View {
var body: some View {
VStack {
Spacer()
Group{
Text("矩形 Rectangle")
Rectangle()
.fill(Color.orange)
.frame(width: 100, height: 100)
}
Group{
Text("圆角矩形 RoundedRectangle")
RoundedRectangle(cornerRadius: 25, style: .continuous)
.fill(Color.red)
.frame(width: 100, height: 100)
}
Group{
Text("胶囊 Capsule")
Capsule()
.fill(Color.green)
.frame(width: 100, height: 50)
Text("椭圆形 Ellipse")
Ellipse()
.fill(Color.blue)
.frame(width: 100, height: 50)
}
Group{
Text("圆形 Circle")
Circle()
.fill(Color.purple)
.frame(width: 100, height: 50)
}
Spacer()
}.background(
Image("zgf")
.resizable()
.aspectRatio(contentMode: .fill)
)
}
}