I am trying to draw simple rectangle inside NSView using code like below:
self.shapeLayer = [CAShapeLayer layer];
self.shapeLayer.lineWidth = 2.0;
self.shapeLayer.strokeColor = [[NSColor whiteColor] CGColor];
self.shapeLayer.fillColor = [[NSColor blackColor] CGColor];
[self.layer addSublayer:self.shapeLayer];
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 400, 400);
CGPathAddLineToPoint(path, NULL, 400, 600);
CGPathAddLineToPoint(path, NULL, 600, 600);
CGPathAddLineToPoint(path, NULL, 600, 400);
CGPathCloseSubpath(path);
// set the shape layer's path
self.shapeLayer.path = path;
I have also tried to draw something in NSView drawRect:
.
In both cases Rectangle gets drawn but it isn't in stroke/fill color set but rather some semitransparent version like alpha 0.5 !
I have tried to draw this Rectangle on NSView placed inside NSWindow that has backgroundColor set to clearColor and opaque to NO. I have then think that there can be something associated with this transparency so I have changed the background color to greenColor and opaque to YES. And I am still getting rectangles drawn with semi-transparency not in vivid solid colors. What am I doing wrong?