在 mac os x 上的计时器应用程序上,我想用绿色、黄色、橙色和红色标记时钟区域。请参阅下面的屏幕截图。我想用透明灰色填充耗时。
但是,正如您在屏幕截图中看到的,只有圆弧段被填充。但我希望整个部门都被填满。我唯一能做的就是[thePath fill];
一如既往,我认为我做错了什么。但什么?
通话
[self drawTheArcWithColor:path1 :liveAngle1 :[NSColor greenColor ] :lineTheWidth];
方法
- (void) drawTheArcWithColor:(NSBezierPath*) thePath :(CGFloat) angle :(NSColor*) theColor :(CGFloat) line {
[thePath setLineWidth:line];
[thePath appendBezierPathWithArcWithCenter:centerPoint radius:2+circleHeight/2 startAngle:angle endAngle:angle+90.0f];
[theColor setStroke];
[[NSColor grayColor] setFill];
[thePath fill];
[thePath stroke];
}
最佳答案
您需要从中心点开始路径,然后添加圆弧段(隐式添加从中心点到圆弧段起点的直线),最后关闭路径(从圆弧段的末尾创建一条隐式直线)到中心点的圆弧段)。
- (void) drawTheArcWithColor:(NSBezierPath*) thePath :(CGFloat) angle :(NSColor*) theColor :(CGFloat) line {
[thePath setLineWidth:line];
[thePath moveToPoint:centerPoint];
[thePath appendBezierPathWithArcWithCenter:centerPoint radius:2+circleHeight/2 startAngle:angle endAngle:angle+90.0f];
[thePath closePath];
[theColor setStroke];
[[NSColor grayColor] setFill];
[thePath fill];
[thePath stroke];
}
关于objective-c - 如何正确填充圆弧扇区 NSBezierPath,Objective-C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14069390/