How to draw text inner shadow on Cocoa for Mac OS X

本小妞迷上赌 提交于 2019-12-21 05:23:07

问题


How do I draw an inner shadow on a text in Cocoa for Mac OS X?

I am subclassing NSView to create a placeholder control with a gradient background and an inner shadowed text title over it.

All current Core Graphics answers on stackoverflow seem to explain drawing text shadows on Cocoa Touch.


回答1:


You might think too complicated. If I get your problem right, the only thing you actually want to do is to set the text style. Then do so by simply using:

[[object cell] setBackgroundStyle:NSBackgroundStyleRaised];

where object is an instance of the class NSTextField.

This handles everything for you. Your gradient background then could be reached for example by using a custom view with a NSGradient. See here

Advantage: You have a proper instance of NSTextField without the need to subclass it or to do other unneeded things like implementing everything a NSTextField does in a subclass of NSView on your own.



来源:https://stackoverflow.com/questions/8752425/how-to-draw-text-inner-shadow-on-cocoa-for-mac-os-x

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