简体   繁体   English

将自定义调色板添加到XCode Interface Builder

[英]Add a custom color palette to XCode Interface Builder

My current long term project utilizes a palette of custom colors. 我目前的长期项目采用了一系列自定义颜色。 In code, we are using a category to access these colors by name. 在代码中,我们使用类别按名称访问这些颜色。 This works great but there are times, such as when building a nib, that these colors won't be set programmatically. 这很有效,但有时候,例如构建笔尖时,这些颜色不会以编程方式设置。

I am looking for a way to define a named set of colors. 我正在寻找一种方法来定义一组命名的颜色。 For instance, when setting a background color for a UIView, I would like my drop list in Interface Builder to list my custom colors by name. 例如,在为UIView设置背景颜色时,我希望Interface Builder中的下拉列表按名称列出我的自定义颜色。 Does anyone know of a way to achieve this? 有谁知道实现这一目标的方法? Thanks! 谢谢!

Xcode 9 Xcode 9

You now have another option to add Color Sets or Named Colors to your assets. 您现在可以使用其他选项将颜色集或命名颜色添加到资源中。 This is new in Xcode 9. 这是Xcode 9中的新功能。

1. Adding Named Colors to Your Project 1.为项目添加命名颜色

添加命名颜色

In *.xcassets > right-click > New Color Set 在* .xcassets>右键单击>新颜色集

2. Assigning Name Colors to Views 2.为视图指定名称颜色

在此输入图像描述

Your new Named Colors show up in your Color Picker now in their own section. 您的新命名颜色现在显示在您的颜色选择器中。

Custom Color Palette 自定义调色板

In the Interface Builder's color dialog, choose the third tab. 在Interface Builder的颜色对话框中,选择第三个选项卡。 Click the gear and New to make a new custom color palette. 单击齿轮和新建以创建新的自定义调色板。 You can name it whatever you want. 您可以随意命名。 Then click the plus (+) button to add a new color and name it. 然后单击加号(+)按钮添加新颜色并命名。 Use the color picker tool to set the color. 使用颜色选择器工具设置颜色。

在此输入图像描述

Colors from RGB or Hex RGB或Hex的颜色

Choose the second tab in the color dialog and select RGB Sliders . 选择颜色对话框中的第二个选项卡,然后选择RGB滑块 This will allow you to set the colors using RGB or hex values. 这将允许您使用RGB或十六进制值设置颜色。

在此输入图像描述

More Help 更多帮助

是的,您可以在IB中创建和编辑调色板,然后与您的团队共享本文包含所有详细信息: http//natashatherobot.com/xcode-color-palette/

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

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