The drawing system passes in the rectangle of the view that needs to be redrawn as the single parameter to drawRect:
You're using that rectangle unconditionally for the path, path = [NSBezierPath bezierPathWithRect:rect];
, assuming that this rect is always the view's full bounds rect. This is not the case. When the button is being hovered over, its frame is the portion of your view which has been invalidated and needs redrawing, and that's what rect
is.
You should either test rect
to make sure it's appropriate to be used for the path, or -- easier and just fine unless you're having measurable drawing-related performance issues -- always use the view's bounds for the outline path.
path = [NSBezierPath bezierPathWithRect:[self bounds]];
The drawing context is going to clip the drawing to the rect it asked for anyways.