views:

640

answers:

2

I'd like to create statusbar with text effect like in Safari or iTunes, i.e. recessed text.

example

However, if I simply add shadow in Interface Builder using Core Animation panel, OS X's worst text rendering kicks in:

wheres my subpixel

What's the trick to get recessed text on a label and keep proper subpixel rendering?

+4  A: 

It's a cheap old trick: You draw the text in white at an offset and then draw the black text on top of it.

There is a hook for shadows in the text-drawing system, NSAttributedString's NSShadowAttributeName. But testing this out, it appears to kill the subpixel antialiasing as well.

Chuck
+1 Makes an awful lot of sense. Nice one.
Wim Hollebrandse
Isn't there a better solution though? One of the numerous OS X text APIs must do it properly...I don't want to add another label, as this will be harder maintain and will probably be annoying for Voice Over users.
porneL
The answer dealt with drawing extra text, not necessarily adding an extra label. You could create a custom subclass of NSTextField with custom drawing code. Then, you only need one label.
Daniel Yankowsky
You don't need to do any of this, NSCell handles it for you. See my answer.
Rob Keniger
@irsk: Good point. I'm leaving mine since it works in any version of OS X while `setBackgroundStyle:` wasn't introduced until Leopard.
Chuck
+12  A: 

There is a built-in way to do this:

[[yourTextField cell] setBackgroundStyle:NSBackgroundStyleRaised];
Rob Keniger