0
votes

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?

Inner Rectangle should be black! But it isn't.

1

1 Answers

0
votes

OK I found the problem. There was added some additional Core Animation Layer I think of the previous view that I have created and then deleted. Then there remain selected this additional Animation Layer in Interface Builder so I deselected it like in the below image and now it works correctly. enter image description here