Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 868
Pheepster Avatar asked Feb 13 '15 13:02

Pheepster


People also ask

How do I add a color palette in XCode?

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.

How do I add custom colors to XCode?

To create a color from our palette, we can do it directly by selecting the Assets. xcassets folder (or creating our own . xcassets folder for colors) in the project navigator (Project Navigator). Then we right click and select New Color Set.

How do I add custom colors in Swift UI?

You need to create a new color by right-clicking anywhere in the list to open a menu, just click Color Set and you name the color however you want. Now open the Inspectors tab in the upper-right of your screen, you will see options that allow you to modify that color set.

How do you add a custom color to a storyboard?

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.


2 Answers

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.

like image 176
Mark Moeykens Avatar answered Sep 24 '22 07:09

Mark Moeykens


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

  • XCode Tip: Color Palette
  • How to define colors in XCodes' Interface Builder?
  • How do I enter RGB values into Interface Builder?
like image 39
Suragch Avatar answered Sep 24 '22 07:09

Suragch