NSButtons leave artifacts when using custom toolbar views as subzones

I place a few buttons in a simple rectangular NSview that acts like a custom toolbar. At the first display, the buttons / views exit as expected, but each time the button is pressed (and sometimes without any interaction with the mouse), artifacts appear.

Before

enter image description here

After

enter image description here

I can eliminate artifacts by calling [self.toolbarView setNeedsDisplay: YES] in all action and focus methods, but it seems to hack, is there any clean way to handle this?

+4
source share
2 answers

This was a beginner's problem. In the drawRect method

- (void)drawRect:(NSRect)dirtyRect 

I used the dirtyRect parameter to draw the outline of my view, assuming these were the borders of the view, where in reality it was just the area around the buttons that became dirty when clicked. The "artifacts" were actually my contours made in the wrong place.

Properly using view boundaries

 NSRect drawingRect = [self bounds]; 

"artifacts" no longer appeared.

+1
source

You are just trying to set the focus ring for the "none" buttons in IB.

0
source

Source: https://habr.com/ru/post/1436156/


All Articles