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

核能气质少年 提交于 2019-12-03 05:08:49

问题


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

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

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


回答1:


There is a built-in way to do this:

[[yourTextField cell] setBackgroundStyle:NSBackgroundStyleRaised];



回答2:


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.



来源:https://stackoverflow.com/questions/1759651/add-shadow-recessed-text-effect-to-cocoa-label-without-degrading-text-renderin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!