使用设计工具创建复杂的 SwiftUI 形状,将设计转换为代码的简单方法

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是可以在许多情况下使用的强大原语。

但是,有些情况下

猜你喜欢

转载自blog.csdn.net/iCloudEnd/article/details/129990414