objective-c - 如何正确填充圆弧扇区 NSBezierPath,Objective-C

标签 objective-c fill nsbezierpath sector

在 mac os x 上的计时器应用程序上,我想用绿色、黄色、橙色和红色标记时钟区域。请参阅下面的屏幕截图。我想用透明灰色填充耗时。

但是,正如您在屏幕截图中看到的,只有圆弧段被填充。但我希望整个部门都被填满。我唯一能做的就是[thePath fill];

一如既往,我认为我做错了什么。但什么?

enter image description here


通话

[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/

相关文章:

ios - 带 pan 1.0 的 Obj-C EZAudioPlot

c++ - 获取多维数组中的第一维

android - 如何用线性渐变填充Android中的路径?

objective-c - 是否可以使用 NSBezierPath 用特定模式填充 NSRect?

objective-c - 有什么简单的方法可以获取 "resize"NSBezierPath 吗?

应用程序被杀死/关闭/未打开时的 IOS 推送通知操作

IOS 7 如何使用 UITableView scrollToRowAtIndexPath

c - 用 0-100 之间的数字填充数组

cocoa NSView : Making circles but they are getting cropped

ios - UITextField.Text 从其他 View 返回 null