How to use Named Color in Xcode 9

Xcode 9 introduced a new feature in asset catalog “Named Color”. Now you can add Color Set to asset catalog instead of using macro or UIColor class function to store colors.

You can add Color Set to Assets.xcassets, but you can also creating a new .xcassets file to store colors which you can manage and copy this fold to other project easily.

Then you can add Color Set and set color value in the Attributes inspector.

Next time designer give you another black color value, you can tell him you already have one and ask him does he really want to add so many black color ?!

To use these colors, I create a UIColor extension.

Since Named Color is only supported on iOS 11, we have to use #available for a while.

In Interface builder, there is a Named Color section anywhere you need color.

Thanks for reading~