Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add shadow (recessed text effect) to Cocoa label without degrading text rendering quality

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?

like image 407
Kornel Avatar asked Nov 18 '09 22:11

Kornel


People also ask

Which feature is used to add a shadow behind the selected text?

Answer. Answer: Select the text or WordArt that you want to format. Under Text Effects, select the Text Effects tab and click Shadow.


2 Answers

There is a built-in way to do this:

[[yourTextField cell] setBackgroundStyle:NSBackgroundStyleRaised];
like image 184
Rob Keniger Avatar answered Oct 04 '22 18:10

Rob Keniger


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.

like image 36
Chuck Avatar answered Oct 04 '22 19:10

Chuck