The Carbon framework has HIThemeBeginFocus() and HIThemeEndFocus() , which allow you to call any series of drawings (for example, a rectangle or shape) for an automatic "focused" appearance. Requires Mac OS X 10.5 or later.
It directly uses Core Graphics. To find the CG context from the drawRect: method in Cocoa, you should do something like:
NSGraphicsContext* contextMgr = [NSGraphicsContext currentContext]; CGContextRef drawingContext = (CGContextRef)[contextMgr graphicsPort];
To avoid cropping, one option is to use a parent view (for example, an NSBox that has no border) to give an extra complement. Perform a custom drawing on an insert in the parent view that will not be cropped; in other words, give the illusion that the view is slightly smaller than its actual rectangle.
source share