I am trying to create a custom UIButton that should look like UIButtonTypeRoundedRect. In my drawRect :, I create a path with the first call to CGContextMoveToPoint (), and then four calls to CGContextAddArc (). Then I will stroke the path. However, in the resulting image, the four rounded corners are obviously thicker than the rest of the path.
I suspected that this had something to do with anti-aliasing, so I tried to disable it using CGContextSetShouldAntiAlias (), but then it looked even worse. I also tried to experiment with line widths, but arcs are always thicker than straight lines. Apple's UIButtonTypeRoundedRect looks great, so it can be solved somehow. Somebody knows?
Edit: corresponding code:
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);