向 Cocoa 标签添加阴影(凹陷文本效果),而不降低文本渲染质量
我想创建带有文本效果的状态栏,如 Safari 或 iTunes 中的文本效果,即凹进文本。
但是,如果我只是使用 Core Animation 面板在 Interface Builder 中添加阴影,OS X 最糟糕的文本渲染就会出现:
在标签上获取凹进文本并保持正确的子像素渲染的技巧是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一种内置方法可以做到这一点:
There is a built-in way to do this:
这是一个廉价的老技巧:在一定偏移处以白色绘制文本,然后在其顶部绘制黑色文本。
文本绘制系统中有一个用于阴影的钩子,即 NSAttributedString 的 NSShadowAttributeName。但经过测试,它似乎也消除了子像素抗锯齿功能。
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.