14

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?

Kornel
  • 97,764
  • 37
  • 219
  • 309

2 Answers2

35

There is a built-in way to do this:

[[yourTextField cell] setBackgroundStyle:NSBackgroundStyleRaised];
Rob Keniger
  • 45,830
  • 6
  • 101
  • 134
  • I don't think so, this is handled internally by the system. You'd need to write your own drawing code to change it. – Rob Keniger Nov 12 '12 at 04:25
6

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
  • 234,037
  • 30
  • 302
  • 389
  • 2
    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. – Kornel Nov 18 '09 at 23:03
  • 1
    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 Nov 18 '09 at 23:42
  • You don't need to do any of this, NSCell handles it for you. See my answer. – Rob Keniger Nov 19 '09 at 08:09
  • 1
    @irsk: Good point. I'm leaving mine since it works in any version of OS X while `setBackgroundStyle:` wasn't introduced until Leopard. – Chuck Nov 19 '09 at 08:18