如何使用描边边框来修剪形状?

use*_*ser 13 swift swiftui

我在 SwiftUI 中修剪后使用描边边界时遇到困难,该怎么办?

\n
Circle()\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

类型“some Shape”的值没有成员“strikeBorder”

\n
\n

\xe2\x9a\xa0\xef\xb8\x8f 至少还有 2 种其他方法可以得到像strokeBorder给出的结果。但他们使用strokeBorder,我想在使用时解决问题strokeBorder

\n

Zoy*_*ler 0

这似乎仍然是一个问题,所以也许这不是一个需要修复的错误。我使用了 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)