相关课程:http://hdjc8.com/hdjc/swiftUI/
使用Rectangle绘制矩形,使用RoundedRectangle绘制圆角矩形。
本节课演示矩形和圆角矩形等图形的绘制,以及如何给图形添加描边效果。
示例代码:
VStack{ Rectangle() //接着修改填充颜色为橙色,并设置它的宽度和高度。 Rectangle() .fill(Color.orange) .frame(width: 200, height: 200) ZStack { Rectangle().fill(Color.purple) .frame(width: 300, height: 200) Rectangle().fill(Color.yellow) .frame(width: 300, height: 200) .scaleEffect(0.8) Rectangle() .fill(Color.orange) .frame(width: 300, height: 200) .scaleEffect(0.6) } //接着绘制一个圆角矩形,并设置它的圆角半径为120。 RoundedRectangle(cornerRadius: 120) //设置圆角的宽度为60,圆角的高度为30。同时设置圆角矩形的宽度为300,高度为200。 RoundedRectangle(cornerSize: CGSize(width: 100, height: 40)).frame(width: 300, height: 200) //绘制一个圆角半径为60的圆角矩形,它的圆角样式为continuous连续型,也就是连续曲率的圆角。 RoundedRectangle(cornerRadius: 100, style: RoundedCornerStyle.continuous) }
查看运行结果: