Color Assets (.xcassets) in Xcode.

Sandeep Kumar
3 min readMar 10, 2019

--

I hope you all are great die hard iOS developers, beginners or freelancers. This article suits for every type of developer working on Xcode making iOS Apps or macOS apps. You all are familiar with storyboards and inserting any UI components inside it and giving colours to background of components via attributes inspector colour option, and going to custom option then manually selecting RGB values of colour selector to pick a specific colour.

You have to repeat manually selecting RGB values step every-time to give colours to components of many viewcontrollers, and each viewcontroller has many UI components.

if somehow you completed your project then client requirement comes or your mind fluctuated from current colour scheme. Then what you will do to change the colours of whole completed app.

Only option here is to change the colours manually of each component in each viewcontroller. So you are going to waste a lot of time and you very well know time is money.

So to avoid problem of changing colours in project you should use Colour assets. colour assets are introduced in Xcode 9.

So to make a colour asset create a new file of type Asset Catalog.

Colors.xcassets

Now open this catalog and right click on empty area to create a new colour asset and name it accordingly.

Now click on big square to provide a specific colour from attributes inspector.

So i’ve created three colour sets.

These colour can be accessed by these names in attributes inspector and via coding also.

In Attributes inspector colour option.

Access colours via name in coding.

UIColor.init(named: “backgroundColor”)

So by using colour assets in xcode project you can solve the problem of colour scheme changes of projects very easily in less time because you have to change your colours in Asset Catalog only.

Thereby save time, money, and party hard 😍 😻 😍

Happy Coding, Do clap if you like it 👏 👏 👏

Other articles you might be interested in:

# 3D Toch Peek and Pop in iOS

# Dynamic height of accessoryView

# Generic way to validate UITextField Responders

# Using .xcconfig files to store various SDK keys and IDs inside Xcode Project.

--

--