2

I've been trying for a day or two to try and get a shadow to draw inside the text of an NSTextField (and making the foreground color transparent, so all you see is a shadow inside the text). I've yet to achieve a desirable and practical result. The only success I had with this was transforming the text into an NSBezerPath, subtracting it from the frame of the NSTextFieldCell and clipping using the setClip method (addClip does not suffice in this case, it leaves the background painted). Unfortunately, converting the text to an NSBezerPath makes the edges of the text look jagged and overly straightened. Is there an efficient and decent way to achieve this using CoreGraphics masks and clipping because I am unable to achieve this.

A very similar effect of what I would be looking for is in the Xcode IDE, if you don't have a debug session open and go to the debugger navigator it says "No Debug Session" in a subclassed NSTextField that draws the text with a shadow inside it. That is pretty nearly what I am after. Any insight on where to start and how to do this would be great.

A paste bin my current code (working, but sub-optimal, & non-working): http://pastebin.com/4pTv8ZWm

TheCrypticAce
  • 173
  • 1
  • 7
  • I thought it was easy, but the problem is that when you draw a shadow id the text has an alpha value of 0, the shadow is not drawn. See here: http://stackoverflow.com/questions/8170678/ios-core-graphics-draw-only-shadows-of-a-cgpath – Ramy Al Zuhouri Feb 12 '13 at 22:59
  • Ok, I think there is some slight miscommunication. I am trying to not use CGPath/NSBezierPath as paths make the text jagged looking because they are anti-aliased differently than text. I did get it working using bezier paths but the text looks really bad, which is why I was searching for a better method. – TheCrypticAce Feb 12 '13 at 23:57

1 Answers1

1

Have you played around with the shadow property of NSTextField in IB? You should be able to get pretty close using a slightly offset shadow effect on the text with the right blend of alpha transparency.

JiuJitsuCoder
  • 1,866
  • 14
  • 13
  • This would only work for outside shadows. The alpha transparency blending [of the text color] would be an issue because it needs to be zero. – TheCrypticAce Feb 12 '13 at 23:57
  • I'm not sure if I should be shocked (or not) that Apple would go through such difficulty to create a label that is shown 10% of the time in the IDE that most Apple users wouldn't ever touch. I'm wondering if they just have a custom font they use for that text.... – JiuJitsuCoder Feb 13 '13 at 19:23
  • I doubt it, but it is possible. I'd check with F-Script but it keeps crashing Xcode, so I'm unable to tell. – TheCrypticAce Feb 13 '13 at 19:29