1

I want to be able to give these ends a corner radius of 5 instead of sharp square ends. lineCap only supports .round, .butt and .square

How can I create a custom corner radius for the lineCap?

Here is the code:

Circle()
    .trim(from: CGFloat(start + offset), to: CGFloat(end - offset))
    .stroke(
        color,
             style: StrokeStyle(
                lineWidth: ringWidth,
                lineCap: .square ,
             )
    )
1

1 Answer 1

1

If you want to keep using Circle().stroke() but just want smoother corners, you can overlay small circles at the endpoints:

ZStack {
    Circle()
        .trim(from: CGFloat(start + offset), to: CGFloat(end - offset))
        .stroke(color, style: StrokeStyle(lineWidth: ringWidth, lineCap: .butt))
    
    // Add rounded caps manually
    Circle()
        .fill(color)
        .frame(width: ringWidth, height: ringWidth)
        .offset(x: /* calculate position for start */)
    
    Circle()
        .fill(color)
        .frame(width: ringWidth, height: ringWidth)
        .offset(x: /* calculate position for end */)
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.