我正在尝试使用 swift 绘制形状,这是我的代码
struct ElementView: View {
var element: Element
var body: some View {
let rec = RoundedRectangle(cornerRadius: 25.0)
return ZStack {
rec
.frame(width: 300, height: 150, alignment: .center)
.foregroundColor(.pink)
.opacity(0.4)
.overlay(
rec.stroke(
Color.pink,
style: StrokeStyle(
lineWidth: 5,
lineCap: .round,
lineJoin: .round
)
)
)
Text("Text")
}
}
}
Run Code Online (Sandbox Code Playgroud)
只有一个边框,但我想要两个或更多
我的结果: https: //i.stack.imgur.com/n26Vb.png
预期内容: https: //i.stack.imgur.com/L23cW.png
如何添加多个边框?
另一种代码更少的方法!
struct ElementView: View {
var body: some View {
Text("Text")
.frame(width: 300, height: 150, alignment: .center)
.background(Color.yellow.opacity(0.4))
.cornerRadius(15.0)
.overlay(RoundedRectangle(cornerRadius: 15.0).strokeBorder(Color.blue, lineWidth: 10.0))
.padding(10.0)
.overlay(RoundedRectangle(cornerRadius: 25.0).strokeBorder(Color.red, lineWidth: 10.0))
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
923 次 |
| 最近记录: |