Swift 如何绘制具有多个边框的形状?
我正在尝试使用swift绘制一个形状,这里是我的代码Swift 如何绘制具有多个边框的形状?,swift,swiftui,Swift,Swiftui,我正在尝试使用swift绘制一个形状,这里是我的代码 struct ElementView: View { var element: Element var body: some View { let rec = RoundedRectangle(cornerRadius: 25.0) return ZStack { rec .frame(width: 300, heigh
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")
}
}
}
只有一个边界,但我想要两个或更多
我的结果是:
预期:
如何添加多个边框?另一种代码更少的方法
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))
}
}