如何在Interface Builder中创建命名颜色? [英] How to create Named colors in Interface Builder?

查看:182
本文介绍了如何在Interface Builder中创建命名颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何设置&在Interface Builder中使用自定义命名颜色?

How do I setup & use custom named colors in Interface Builder?

推荐答案

在Xcode9中,您可以将新颜色集添加到 .xcassets 文件,您可以在其中设置rgba值或使用IB的颜色选择器。

In Xcode9 you can add "New Color Set" to .xcassets files, where you can set rgba values or use IB's color picker.

然后你可以使用Interface Builder的颜色选择器中新定义的颜色,它出现在命名颜色部分下。

Then you can use that newly defined color from Interface Builder's color picker, it appears under the Named Colors section.

或者您可以使用i来自代码,如 UIColor(名称:customColorName)

Or you can use it from code like UIColor(named:"customColorName").

目前,Xcode9 beta 1没有支持使用字符串文字颜色名称作为UIColor(就像它适用于UIImages),但我希望它可以在以后的版本中使用。

As for now, Xcode9 beta 1 does not support using string literal color names as UIColor (like it works with UIImages), but I hope it will work in a later release.

不幸的是,它仅适用于iOS11及更高版本。

Unfortunatelly it's only available for iOS11 and later.

这篇关于如何在Interface Builder中创建命名颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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