ios 向 XCode Interface Builder 添加自定义调色板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28501010/
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
Add a custom color palette to XCode Interface Builder
提问by Pheepster
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. Does anyone know of a way to achieve this? Thanks!
我正在寻找一种方法来定义一组命名的颜色。例如,在为 UIView 设置背景颜色时,我希望 Interface Builder 中的下拉列表按名称列出我的自定义颜色。有谁知道实现这一目标的方法?谢谢!
采纳答案by Jerry
Yes, you can create and edit a palette in IB and then share it with your team This article has all the details: http://natashatherobot.com/xcode-color-palette/
是的,您可以在 IB 中创建和编辑调色板,然后与您的团队分享本文包含所有详细信息:http: //natashatherobot.com/xcode-color-palette/
回答by Mark Moeykens
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.
您的新命名颜色现在显示在您的拾色器中各自的部分。
回答by Suragch
Custom Color Palette
自定义调色板
In the Interface Builder's color dialog, choose the third tab. Click the gear and Newto 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.
在 Interface Builder 的颜色对话框中,选择第三个选项卡。单击齿轮和新建以创建新的自定义调色板。您可以随意命名。然后单击加号 (+) 按钮以添加新颜色并为其命名。使用颜色选择器工具设置颜色。
Colors from RGB or Hex
RGB 或十六进制的颜色
Choose the second tab in the color dialog and select RGB Sliders. This will allow you to set the colors using RGB or hex values.
选择颜色对话框中的第二个选项卡,然后选择RGB Sliders。这将允许您使用 RGB 或十六进制值设置颜色。