作者:劈腿年代shui还相信真爱 | 来源:互联网 | 2023-10-13 12:42
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.
我已经尝试了一两天尝试在NSTextField的文本中绘制阴影(并使前景色透明,所以你看到的只是文本中的阴影)。我还没有达到理想和实用的结果。我唯一的成功就是将文本转换为NSBezerPath,从NSTextFieldCell的帧中减去它并使用setClip方法剪切(addClip在这种情况下不够,它会留下背景画)。不幸的是,将文本转换为NSBezerPath会使文本边缘看起来呈锯齿状并过度拉直。有没有一种有效且体面的方法来使用CoreGraphics蒙版和剪辑来实现这一点,因为我无法实现这一点。
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.
我将要寻找的非常类似的效果是在Xcode IDE中,如果你没有打开调试会话并转到调试器导航器,它会在子类NSTextField中显示“No Debug Session”,该文件使用里面的影子。这几乎就是我所追求的。任何有关如何开始以及如何做到这一点的见解都会很棒。
A paste bin my current code (working, but sub-optimal, & non-working): http://pastebin.com/4pTv8ZWm
一个粘贴箱我当前的代码(工作,但次优,不工作):http://pastebin.com/4pTv8ZWm
1 个解决方案