I'm placing a few buttons in a simple rectangular NSview which acts as a custom toolbar. On first render the buttons/views come out as expected, but every time a button is pressed (and sometimes with no mouse interaction at all) artefacts start appearing.

Before

enter image description here

After

enter image description here

I can eliminate the artefacts by calling a [self.toolbarView setNeedsDisplay:YES] in all the action and focus methods but this seems like a hack, is there any clean way to deal with this?

有帮助吗?

解决方案

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

- (void)drawRect:(NSRect)dirtyRect

I was using the param dirtyRect for drawing an outline of my view, assuming it was the view's bounds, where in fact it was only the area around the buttons that became dirty when they were pressed. The 'artefacts' were actually my outline being drawn in the wrong place.

By correctly using the bounds of the view

NSRect drawingRect = [self bounds];

the 'artefacts' no longer appeared.

其他提示

You just try to set focus ring for a buttons to 'none' in IB.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top