简体   繁体   中英

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. Does anyone know of a way to achieve this? Thanks!

Xcode 9

You now have another option to add Color Sets or Named Colors to your assets. This is new in Xcode 9.

1. Adding Named Colors to Your Project

添加命名颜色

In *.xcassets > right-click > New Color Set

2. Assigning Name Colors to Views

在此输入图像描述

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. 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

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.

在此输入图像描述

More Help

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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