原文链接:https://github.com/fzhlee/SwiftUI-Guide#-%E7%AC%AC31%E8%8A%82shape-rectangle-
使用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)
}
RoundedRectangle(cornerRadius: 120) //绘制一个圆角矩形,并设置它的圆角半径为120
RoundedRectangle(cornerSize: CGSize(width: 100, height: 40)).frame(width: 300, height: 200) //设置圆角的宽度为100,圆角的高度为40
RoundedRectangle(cornerRadius: 100, style: RoundedCornerStyle.continuous) //圆角样式为continuous连续型,也就是连续曲率的圆角
}
![](https://img.haomeiwen.com/i2466108/2ba5dccf57e521e5.png)
网友评论