简体   繁体   English

Cocoa中文本阴影的首选方法

[英]Preferred method for text shadow in Cocoa

I have created a Mac app and need to place a shadow behind the white letters to better differentiate the text from the background. 我创建了一个Mac应用程序,需要在白色字母后面放置一个阴影,以便更好地区分文本和背景。 I noticed that I can use the "View Effects Inspector" in Interface Builder to add a drop shadow to static text. 我注意到我可以使用Interface Builder中的“视图效果检查器”为静态文本添加投影。 Is this the preferred method of doing this? 这是首选方法吗? I've seen examples of implementing by code but is it fine to use the Interface Builder approach? 我已经看到了通过代码实现的例子,但使用Interface Builder方法是否合适?

I'm not sure that there is a "preferred" method. 我不确定是否有“首选”方法。 The interface builder method works well and I personally haven't had any issues with it. 界面构建器方法运行良好,我个人没有任何问题。 You could take the code route and use NSShadowAttributeName (See this doc for more) to add a shadow to an NSAttributedString . 您可以使用代码路由并使用NSShadowAttributeName (有关更多信息,请参阅文档)以向NSAttributedString添加阴影。 In the end, either way you choose shouldn't matter. 最后,无论你选择哪种方式都无所谓。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM