Smoothing a rounded stroke in Core Graphics

后端 未结 2 1193
一个人的身影
一个人的身影 2020-12-19 15:46

I am creating my own UITableViewCells with a gradient background. I have all the logic and drawing worked out, but one thing I want to fix is the \"chunkiness\" around the

2条回答
  •  一个人的身影
    2020-12-19 16:23

    Your line width is set to 2 points. What's happening is that your code is calculating your bounding rect without understanding the width of the line. The result is that for every straight segment of your shape, only half of the stroke's width is visible. On the arc, the full stroke width is visible.

    Here's the relevant segment of code from my app, Funversation, to draw the playing cards with rounded corners similar to what you have.

    CGRect rect = [self bounds];
    rect.size.width -= lineWidth;
    rect.size.height -= lineWidth;
    rect.origin.x += lineWidth / 2.0;
    rect.origin.y += lineWidth / 2.0;
    

    Add that before your calculation for minx, midx, maxx, etc. and the strokes for your shape should be uniform.

提交回复
热议问题