带边框的iOS UIImage具有较粗的角半径

mic*_*ahl 5 core-graphics objective-c uiimage ios paintcode

我正在尝试使用具有边框和角半径的CoreGraphics(通过PaintCode)在代码中构建UIImage.我发现图像边缘有一个明显更厚的边框.这似乎是一个iOS错误或我完全遗漏的东西.请指教.

码:

CGRect rect = CGRectMake(0, 0, 53, 100);

//// UIGraphics for UIImage context
CGContextRef context = UIGraphicsGetCurrentContext();
UIGraphicsPushContext(context);
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);

//// Rectangle Drawing
UIBezierPath *rectanglePath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:cornerRadius];
[backgroundColor setFill];
[rectanglePath fill];
[borderColor setStroke];
rectanglePath.lineWidth = 1.4;
[rectanglePath stroke];

//// UIBezierPath to Image
CGContextAddPath(context, rectanglePath.CGPath);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsPopContext();
UIGraphicsEndImageContext();

return image;
Run Code Online (Sandbox Code Playgroud)

图片:

角半径较粗

这是1的lineWidth和60的宽度,它看起来仍然有点厚:

在此输入图像描述

mic*_*ahl 5

对于那些在家中跟随的人:

感谢@ PixelCutCompany的帮助,我需要插入UIBezierPath的边界,以便边框不会超出我正在绘制的图像的框架。

修改代码如下,lineWidth 为 1。

CGRect boundedRectForRadius = CGRectMake(1, 1, 58, 98);
UIBezierPath *rectanglePath = [UIBezierPath bezierPathWithRoundedRect:boundedRectForRadius cornerRadius:cornerRadius];
Run Code Online (Sandbox Code Playgroud)

没有这个,它会像这样裁剪图像:

在此处输入图片说明