开发者

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

开发者 https://www.devze.com 2022-12-12 01:32 出处:网络
I\'d like to create statusbar with text effect like in Safari or iTune开发者_如何学编程s, i.e. recessed text.

I'd like to create statusbar with text effect like in Safari or iTune开发者_如何学编程s, i.e. recessed text.

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

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

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

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


There is a built-in way to do this:

[[yourTextField cell] setBackgroundStyle:NSBackgroundStyleRaised];


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消