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!
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.
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.
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.
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.
You now have another option to add Color Sets or Named Colors to your assets. This is new in Xcode 9.
In *.xcassets > right-click > New Color Set
Your new Named Colors show up in your Color Picker now in their own section.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With