SwiftUI from entry to actual combat Chapter 2 Section 10: Shape-Circle

Related courses: http://hdjc8.com/hdjc/swiftUI/

In SwiftUI, you can easily draw a variety of graphs. You will draw a variety of complex and beautiful graphs and charts in Chapters 7 and 8. This lesson will first demonstrate the drawing of simple circles.

Use Circle to draw a circle, and set the circle's fill color, display area and other attributes.


Sample code:

VStack{
    //绘制一个圆形,它的填充颜色默认是黑色。
    Circle()

    //通过调用它的fill方法,给圆形填充橙色。
    Circle()
	.fill(Color.orange)
	.frame(width: 200, height: 200)//然后将圆形的宽度和高度都设置为200。
    ZStack {
        //然后绘制一个圆形,并设置填充颜色为紫色。
       Circle().fill(Color.purple)
        //绘制另一个圆形,其填充颜色为黄色,并将尺寸缩小到原来的0.8倍。
       Circle().fill(Color.yellow).scaleEffect(0.8)
        //绘制最后一个圆形,其填充颜色为橙色,并将尺寸缩小到原来的0.6倍。
       Circle().fill(Color.orange).scaleEffect(0.6)
    }

    //绘制一个简单的矩形,它的默认填充颜色为黑色。
    Rectangle()
    //接着修改填充颜色为橙色,并设置它的宽度和高度。
    Rectangle()
	.fill(Color.orange)
	.frame(width: 200, height: 200)
    ZStack {
       Rectangle().fill(Color.purple)
	.frame(width: 300, height: 200)

    //接着绘制另一个黄色的矩形,并将它缩小到原来的0.8倍。
       Rectangle().fill(Color.yellow)
	.frame(width: 300, height: 200)
	.scaleEffect(0.8)

    //使用相同的方式,绘制第三个橙色的矩形,并将它缩小到原来的0.6倍。这样就绘制了在垂直屏幕的方向上进行叠加的三个矩形。
       Rectangle()
	.fill(Color.orange)
	.frame(width: 300, height: 200)
	.scaleEffect(0.6)
    }
}

View the results of the operation:

Guess you like

Origin blog.csdn.net/fzhlee/article/details/106147868