Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use strokeBorder for trimmed Shapes?

Tags:

swift

swiftui

I have difficulty to use strokeBorder after trim in SwiftUI, how can do this?

Circle()
  .trim(from: 0, to: 0.5)
  .strokeBorder(Color.red, style: StrokeStyle(lineWidth: 50.0, lineCap: .round, lineJoin: .round))

Error:

Value of type 'some Shape' has no member 'strokeBorder'

⚠️ There are at least 2 other ways to get the result like strokeBorder gives. But they are NOT using strokeBorder, I want to solve the issue while using strokeBorder.

like image 801
ios coder Avatar asked Jan 30 '26 01:01

ios coder


1 Answers

This still seems to be a problem, so maybe it's not a bug to be fixed. I used the same solution suggested by aheze, but having the lineWidth as a variable or constant helps, especially if there are additional layers that need to be added. For instance, any additional Shapes/Images that need to layered on top would also need to have this additional padding to keep things aligned.

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)
like image 104
ZoydWheeler Avatar answered Feb 01 '26 16:02

ZoydWheeler