Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ranguvar

macrumors 6502
Original poster
Sep 18, 2009
318
2
Hi,

Normally in OS X apps, if you unfocus your app's window, e.g. by clicking on the desktop, buttons / toolbars / other controls will change their appearance (it looks as if they were shaded by a light gray or something...).
When I subclass e.g. NSButtonCell, how do I check if it is in its normal state or in this gray / shaded state?

Thanks,

-ranguvar

EDIT: Okay, here's how you do it:

In your drawRect: (or corresponding) method, include the following:
Code:
if (self == [[self window] firstResponder]
   && [[self window] isMainWindow]
   && [[self window] isKeyWindow])
{
   // Draw focused version.
}
else {
   // Draw unfocused version.
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.