gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 19:22:43 25 4
gpt4 key购买 nike

这是我的代码:

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);

为什么不在形状周围绘制边框?

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

http://cl.ly/0u0e051a060m161u0n08

最佳答案

使用CGContextDrawPath(context, kCGPathFillStroke)代替CGContextFillPath()CGContextStrokePath()

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

关于iphone - 为什么我的CoreGraphics形状不显示边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9382306/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com