问题
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