SwiftUI 为我们的项目提供了 5 种内置形状。
它们是Rectangle, RoundedRectangle(具有角半径参数)、Capsule、Ellipse和Circle。
让我们看看它的实际效果:
struct ShapesView: View {
var body: some View {
VStack (spacing: 10) {
Rectangle()
.fill(.pink)
.frame(width: 100, height: 50)
RoundedRectangle(cornerRadius: 10, style: .continuous)
.fill(.purple)
.frame(width: 100, height: 100)
Capsule()
.fill(.blue)
.frame(width: 150, height: 150)
Ellipse()
.fill(.red)
.frame(width: 150, height: 100)
Circle()
.fill(.green)
.frame(width: 150, height: 250)
}
}
}
结果是:
Shapes并且Paths是可以在许多情况下使用的强大原语。
但是,有些情况下