如何在 Xcode 故事板颜色选择器中添加自定义颜色?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36474035/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:42:04  来源:igfitidea点击:

How to add custom color in Xcode storyboard color picker?

iosxcode

提问by Saood

I am planning to make theme color of UI elements in application. how we show custom color(Golden Color) like Black color in picker menu

我打算在应用程序中制作 UI 元素的主题颜色。我们如何在选择器菜单中显示自定义颜色(金色),如黑色

enter image description here

在此处输入图片说明

is it possible? like we can add custom Property as shown in snapshoenter image description heret

是否可以?就像我们可以添加自定义属性,如图snapsho 在此处输入图片说明ŧ

回答by Mahendra

You can add custom color as folow

您可以添加自定义颜色如下

  1. Select color property(Background color, text color, etc.). A popup is shown from that select "other" option.
  1. 选择颜色属性(背景颜色、文本颜色等)。从该选择的“其他”选项中显示一个弹出窗口。

enter image description here

在此处输入图片说明

  1. A color picker will be opened. Here you can set your custom color by RGB/Hex Code and you can set opacity.
  1. 将打开一个颜色选择器。在这里,您可以通过 RGB/十六进制代码设置自定义颜色,还可以设置不透明度。

enter image description here

在此处输入图片说明

The color will be applied and visible under "Recently Used Colors". This is how you can add custom colors but as far as I know you can't add colors in that default list.

颜色将在“最近使用的颜色”下应用并可见。这是您可以添加自定义颜色的方法,但据我所知,您无法在该默认列表中添加颜色。

回答by SeNeO

Create a new palette by clicking "New" here: enter image description here

单击此处的“新建”创建一个新调色板: 在此处输入图片说明

A new palette "Unnamed" will be created. You can rename that palette by clicking the cog again and choosing "Rename..." Then, you'll need to click on the objects you want to capture the color of, and drag the color of those objects into the color chip area:

将创建一个新的调色板“未命名”。您可以通过再次单击齿轮并选择“重命名...”来重命名该调色板,然后,您需要单击要捕获其颜色的对象,并将这些对象的颜色拖到颜色芯片区域中:

enter image description here

在此处输入图片说明

Once you've captured the color, you can even rename it something that indicates where it's normally used, providing more information to the recipient than just the color.

捕获颜色后,您甚至可以将其重命名为指示其通常使用位置的名称,从而为接收者提供更多信息,而不仅仅是颜色。

source

来源

回答by Matt

As of Xcode 9 you can add colors to your asset catalog. Open your asset catalog, click the + and add a color set. Click on the color that was created and you can name it and set the color using the inspector. Thereafter that color shows up in storyboard color chooses in the area called Named Colors.

从 Xcode 9 开始,您可以向资产目录添加颜色。打开您的资产目录,单击 + 并添加颜色集。单击创建的颜色,您可以命名它并使用检查器设置颜色。此后,该颜色显示在名为“命名颜色”的区域中的故事板颜色选择中。