Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom NSView draws over controls on top of it
    primarykey
    data
    text
    <p>I have an <code>NSView</code> with a custom subclass that draws a grid of rounded rectangles inside it. This <code>NSView</code> was placed with interface builder and on top of it I have some <code>NSButton</code>s. </p> <p>The problem is that sometimes when the view is re-drawn (ie, when i click a button on top of it) then it re-draws over some of the buttons that are meant to stay on top. When this happens only the smaller rounded rects appear over the buttons though, not the background one that is drawn before the loop.</p> <p>Here is the code form drawRect:</p> <pre><code>[NSGraphicsContext saveGraphicsState]; NSBezierPath *path = [NSBezierPath bezierPathWithRect:self.bounds]; [[NSColor grayColor] set]; [path fill]; [NSGraphicsContext restoreGraphicsState]; for( int r = 0; r &lt; 15; r++ ){ for( int c = 0; c &lt; 15; c++ ) { [NSGraphicsContext saveGraphicsState]; // Draw shape NSRect rect = NSMakeRect(20 * c, 20 * r, 15, 15); NSBezierPath *roundedRect = [NSBezierPath bezierPathWithRoundedRect: rect xRadius:1 yRadius:1]; [roundedRect setClip]; // Fill [[NSColor colorWithCalibratedHue:0 saturation:0 brightness:0.3 alpha:1] set]; [roundedRect fill]; // Stroke [[NSColor colorWithCalibratedHue:0 saturation:0 brightness:0.5 alpha:1] set]; [roundedRect setLineWidth:2.0]; [roundedRect stroke]; [NSGraphicsContext restoreGraphicsState]; } } </code></pre> <p>Here's a screenshot: <img src="https://i.stack.imgur.com/yvLgY.png" alt="Screenshot"></p> <p><strong>Update:</strong> Simplified the code, added a screenshot.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload