在MacOS上的椭圆形CAShapeLayer周围绘制边框

问题描述 投票:0回答:1

我需要显示一个具有预定义fillColor和1px borderColor的椭圆形图层。这里是代码:

    CGRect r = CGRectMake(28, self.bounds.size.height - 5 - 12, 12.0, 12.0);
    NSBezierPath *path = [NSBezierPath bezierPathWithOvalInRect:r];

    NSColor *fillColor = [NSColor colorWithRed:255.0/255.0 green:193.0/255.0 blue:47.0/255.0 alpha:1.0f];
    NSColor *borderColor = [NSColor colorWithRed:226.0/255.0 green:70.0/255.0 blue:84.0/255.0 alpha:1.0f];

    minimizeButtonLayer = [CAShapeLayer layer];
    minimizeButtonLayer.path = path.CGPath;
    minimizeButtonLayer.fillColor = fillColor.CGColor;
    minimizeButtonLayer.borderColor = borderColor.CGColor;
    minimizeButtonLayer.borderWidth = 1.0;

椭圆形正确显示,但没有任何边框。为什么?请帮助我。

P.S。请注意,path.CGPath来自NSBezierPath类别。

objective-c macos io core-graphics
1个回答
0
投票

我通过将strokeColor替换为strokeColor解决了问题

minimizeButtonLayer.borderColor = borderColor.CGColor;

with

minimizeButtonLayer.strokeColor = borderColor.CGColor;
© www.soinside.com 2019 - 2024. All rights reserved.