Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force redraw of custom cocoa control on property change

Lets say I have a custom control called FooBox. It is just a square on the screen. It has some properties like color, border, etc. When I change the properties, I want the FooBox to redraw itself to reflect its new properties. Is there a way to do that without writing custom setters and putting [self setNeedsDisplay:YES] into all of them?

like image 335
Randall Avatar asked Feb 27 '23 10:02

Randall


1 Answers

I am not certain if this is the right way to do it, but you could consider using NSKeyValueObserving and register the object as observer of itself, and do the redrawing in the -observeValueForKeyPath:ofObject:change:context: method.

like image 127
Johan Kool Avatar answered Mar 07 '23 17:03

Johan Kool