我在 SwiftUI 中修剪后使用描边边界时遇到困难,该怎么办?
\nCircle()\n .trim(from: 0, to: 0.5)\n .strokeBorder(Color.red, style: StrokeStyle(lineWidth: 50.0, lineCap: .round, lineJoin: .round))\n
Run Code Online (Sandbox Code Playgroud)\n错误:
\n\n\n类型“some Shape”的值没有成员“strikeBorder”
\n
\xe2\x9a\xa0\xef\xb8\x8f 至少还有 2 种其他方法可以得到像strokeBorder
给出的结果。但他们不使用strokeBorder
,我想在使用时解决问题strokeBorder
。
这似乎仍然是一个问题,所以也许这不是一个需要修复的错误。我使用了 aheze 建议的相同解决方案,但将 lineWidth 作为变量或常量会有所帮助,特别是在需要添加其他层的情况下。例如,任何需要分层在顶部的附加形状/图像也需要具有附加的填充以保持对齐。
let lineWidth: CGFloat = 50.0
Circle()
.trim(from: 0, to: 0.5)
.stroke(Color.red, style: StrokeStyle(lineWidth: lineWidth, lineCap: .round, lineJoin: .round))
.padding(lineWidth / 2)
Run Code Online (Sandbox Code Playgroud)