我正在尝试创建一个自定义的UIButton,它看起来应该像UIButtonTypeRondRect。在我的drawRect:中,我正在创建一个路径,第一个调用CGContextMoveToPoint(),然后四个调用CGContextAddArc()。然后我划过这条路。但是,在生成的图像中,四个圆角明显比路径的其余部分厚。
我怀疑这与抗锯齿有关,所以我尝试用CGContextSetShouldAntiAlias()将其关闭,但结果看起来更糟。我也尝试过线宽,但圆弧总是比直线粗。苹果的UIButtonyPeroundRect看起来非常好,所以一定有可能以某种方式解决。有人有线索吗?
编辑:相关代码:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextBeginPath(context);
CGContextMoveToPoint(context, rect.origin.x + kRoundedRectButtonRadius, rect.origin.y);
CGContextAddArc(context, rect.origin.x + rect.size.width - kRoundedRectButtonRadius, rect.origin.y + kRoundedRectButtonRadius, kRoundedRectButtonRadius, 3 * M_PI_2, 0, NO);
CGContextAddArc(context, rect.origin.x + rect.size.width - kRoundedRectButtonRadius, rect.origin.y + rect.size.height - kRoundedRectButtonRadius, kRoundedRectButtonRadius, 0, M_PI_2, NO);
CGContextAddArc(context, rect.origin.x + kRoundedRectButtonRadius, rect.origin.y + rect.size.height - kRoundedRectButtonRadius, kRoundedRectButtonRadius, M_PI_2, M_PI, NO);
CGContextAddArc(context, rect.origin.x + kRoundedRectButtonRadius, rect.origin.y + kRoundedRectButtonRadius, kRoundedRectButtonRadius, M_PI, 3 * M_PI_2, NO);
CGContextClosePath(context);
CGContextSetLineWidth(context, 1.7);
CGContextStrokePath(context);