Why does a CAShapeLayer's stroke extend out of the frame?

后端 未结 2 736
灰色年华
灰色年华 2021-02-18 18:48

Here\'s sample code:

//Called by VC:

HICircleView *circleView = [[HICircleView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];

// init of circle view

- (id)         


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-02-18 19:06

    Setting the lineWidth draws a line, where the actual path is exactly in the middle of the drawn line.

    If you want the drawn line to line up with something, you will have to shift the path by half the lineWidth.

    You can shift the path by using - (void)applyTransform:(CGAffineTransform)transform on UIBezierPath and apply a translate transform.

    If you want a drawn path to be contained in a certain area, shifting the path doesn't help. In that case just create a smaller path. If you want to draw a 100ptx100pt rect with a line width of 5, you have to draw a path in a 95pt*95pt rect (2.5pt space on either side).

提交回复
热议问题