如何绘制文本内阴影在Cocoa的Mac OS X [英] How to draw text inner shadow on Cocoa for Mac OS X

查看:196
本文介绍了如何绘制文本内阴影在Cocoa的Mac OS X的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Cocoa for Mac OS X的文本上绘制内部阴影?

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

我是NSView的子类,创建一个带有渐变背景和内部阴影文本标题的占位符控件。

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

所有当前Core Graphics的解决方案stackoverflow似乎解释了在Cocoa Touch上绘制文本阴影。

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

推荐答案

你可能会觉得太复杂。如果我的问题正确,你实际想要做的只是设置文本样式。然后通过简单使用:

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];

其中object是类NSTextField的实例。

where object is an instance of the class NSTextField.

这为你处理一切。然后可以通过使用具有NSGradient的自定义视图来达到您的渐变背景。请参见此处

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

优点:你有一个适当的NSTextField实例,而不需要子类化或做其他不需要的事情,像实现一个NSTextField在NSView的子类中自己做的。

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.

这篇关于如何绘制文本内阴影在Cocoa的Mac OS X的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆