Nicholas Credli
Nicholas Credli

Reputation: 906

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

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.

Upvotes: 4

Views: 741

Answers (1)

pbx
pbx

Reputation: 1137

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.

Upvotes: 4

Related Questions