Iphone 为什么我的CoreGraphics形状不显示边框?

Iphone 为什么我的CoreGraphics形状不显示边框?,iphone,ios,core-graphics,Iphone,Ios,Core Graphics,这是我的代码: CGContextRef context = UIGraphicsGetCurrentContext(); CGContextClearRect(context, rect); CGContextSetFillColorWithColor(context, [BUTTON_COLOR CGColor]); CGContextSetStrokeColorWithColor(context, [[UIColor blackColor] CGColor]); CGContextSet

这是我的代码:

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, rect);

CGContextSetFillColorWithColor(context, [BUTTON_COLOR CGColor]);
CGContextSetStrokeColorWithColor(context, [[UIColor blackColor] CGColor]);
CGContextSetLineWidth(context, 1);

int radius = CORNER_RADIUS;

CGContextMoveToPoint(context, 0, self.frame.size.height / 2);
CGContextAddLineToPoint(context, POINT_WIDTH, self.frame.size.height);
CGContextAddLineToPoint(context, rect.origin.x + rect.size.width - radius, 
                            rect.origin.y + rect.size.height);
CGContextAddArc(context, rect.origin.x + rect.size.width - radius, 
                    rect.origin.y + rect.size.height - radius, radius, M_PI / 2, 0.0f, 1);
CGContextAddLineToPoint(context, rect.origin.x + rect.size.width, rect.origin.y + radius);
CGContextAddArc(context, rect.origin.x + rect.size.width - radius, rect.origin.y + radius, 
                    radius, 0.0f, -M_PI / 2, 1);
CGContextAddLineToPoint(context, POINT_WIDTH, 0);
CGContextAddLineToPoint(context, 0, self.frame.size.height / 2);

CGContextClosePath(context);
CGContextDrawPath(context, kCGPathFillStroke);
为什么不在形状周围绘制边框

编辑:由于更改了最后一条线,现在它绘制了形状,但它在其周围绘制了一条额外的线,如下所示:


使用
CGContextDrawPath(context,kCGPathFillStroke)
而不是
CGContextFillPath()
CGContextStrokePath()


问题是,在第一次调用
CGContextFillPath()
CGContextStrokePath()
后,上下文的路径被清除,因此第二次调用没有路径可以使用。

链接图片可能会有所帮助。这画出了一条线,但问题是,它也画出了形状的周围,就像这样:它对我来说很好。您确定没有为视图(或其superview)设置角半径和边框吗?外边界肯定是在别处画的。