1.8_如何显示几何形状

如果我们想在应用程序中使用简单的几何形状,我们可以直接创建它们,然后根据需要对它们进行着色和定位。

1. 矩形

例如,如果我们想要一个 200x200 红色矩形,可以使用如下代码:

struct ContentView: View {
    var body: some View {
        // 1. 200 * 200 红色矩形
        Rectangle()
            .fill(Color.red)
            .frame(width: 200, height: 200)
    }
}

效果预览: 1.8_square_red_wh200

2. 圆

同样,如果你想要一个 50x50 的蓝色圆圈,您可以使用如下代码:

struct ContentView: View {
    var body: some View {
        // 2. 50 * 50 蓝色圆圈
        Circle()
            .fill(Color.blue)
            .frame(width: 50, height: 50)
    }
}

效果预览: 1.8_circle_blue_r50

Avatar
M X
Mobile, Front-End Developer

My research interests include swift developing, python developing and go developing.

Related

Next
Previous
comments powered by Disqus