open source

Developer: NSButton drawing issue

A post for developers, though also related to Time Out 2.

One of the features of Time Out 2 is a sidebar listing the breaks and options, as you could see (blurred somewhat) in my previous post . The sidebar includes a couple of buttons that appear when you hover the pointer over a row, enabling you to manually start or pause that break.

A vexing issue I had, though, was that the button didn't draw correctly. If you look closely at this screenshot, you may notice that the background of the text and the remainder of the button content don't match — there's a visible outline around the text:

That is rather ugly. I'm not sure exactly what causes it, but presumably it's related to being in a sidebar list, and perhaps an issue with title-less windows (I've seen some other issues, too).

Regardless, I wanted to fix it. After a bit of experimentation, I found a simple solution: a subclass of NSButtonCell to override the -drawTitle:withFrameinView: method, which as you might imagine is responsible for drawing the title text. The override simply invokes the superclass, and returns the full button rect instead of the rect of the text itself:

@interface DejalButtonCell : NSButtonCell


@implementation DejalButtonCell

- (NSRect)drawTitle:(NSAttributedString *)title withFrame:(NSRect)frame inView:(NSView *)controlView;
    [super drawTitle:title withFrame:frame inView:controlView];
    return frame;


That seems to do the trick:

Filed Radar #22491410.

Syndicate content