1
votes

I am subclassing NSView and implementing my own slider control (it is easier with NSView than NSControl I think), and thus I am implementing the "drawRect" method in that view.

I also implement "mouseDragged" method and calculate the position of the knob and then i call [self setNeedsDisplay:YES] to make the NSView subclass redraw.

The problem is that when I call [self setNeedsDisplay:YES] the NSView draws a grey background and border (looks like a rounded rect), but I do not draw this in the "drawRect" method and this border and background goes away as soon as I resize the superview.

What causes this background/border draw and how can I prevent it?

3
I found a way. If I call "[self.superview setNeedsDisplay:YES]" it all works. Is that a good solution? - Neigaard

3 Answers

1
votes

In your drawrect method include this line:-

     [super drawRect:rect];
0
votes

I find that [super drawRect:rect] isn't performing well, but [super setNeedsDisplay:YES] does.

0
votes

I found that the code from the comment:

[self.superview setNeedsDisplay:YES]

worked, but not the one in the accepted answer. Just posting this for anyone else out there looking for a solution.