50

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?

pkamb
  • 33,281
  • 23
  • 160
  • 191
Pheepster
  • 6,045
  • 6
  • 41
  • 75

3 Answers3

100

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

Adding Named Colors

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

2. Assigning Name Colors to Views

enter image description here

Your new Named Colors show up in your Color Picker now in their own section.

Community
  • 1
  • 1
Mark Moeykens
  • 15,915
  • 6
  • 63
  • 62
38

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.

enter image description here

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.

enter image description here

More Help

Community
  • 1
  • 1
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
  • 6
    The first solution in this answer will create a .clr file in "~/Library/Colors" which you can add to your project Supporting Files folder and share with your team ;) – Ramin Jun 20 '19 at 17:51
30

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/

Edit: That link has expired. You can see the web archive here: https://web.archive.org/web/20210303015055/http://natashatherobot.com/xcode-color-palette/

But, using named colors in the asset catalog is a better way to go now.

Jerry
  • 4,382
  • 2
  • 35
  • 29
  • 8
    links can expire, can you provide more details for the solution. – Lunarchaos42 Apr 24 '18 at 20:43
  • But may it also support Dark Mode? Like May I choose 2 colors?? One for Dark Mode and One for Light Mode?? – Kautsya Kanu Nov 24 '20 at 21:10
  • each "color" in asset catalog (as of 2022, not sure since when) is actually two colors — "any appearance" and "dark" ... and you can split that into "any", "light", and "dark" or reduce it to just "any" ... crazy configurable. :) – Kaolin Fire Feb 11 '22 at 00:56