Asset Color Catalog | Swift Tutorial

Asset Color Catalog is the feature of XCode 9. BY the use of this feature we can maintain the colors easily and avoid the mistakes. We can create the color catalog in 

1
.xcassets

 and use that color in all over se of color name.

Creating color set in asset catalog (

1
.xcassets

)

Select the .xcassets directory in Xcode and select the 

1
plus

 button on the bottom left and select 

1
New Color Set

. Change the name of your color at right top corner and change the color RGB value according to you. Make sure your color name is unique to other color which are defined by you in same project.

 

Asset catalog colors in Storyboards

We can use this asset catalog color in Storyboard and Interface Builder file. When you selecting the color for views, You can see your color under the “Named colors”.

Asset catalog colors by code


1
2
3
4
5
6
<span class="hljs-keyword">let</span> color: <span class="hljs-type">UIColor</span>
<span class="hljs-keyword">if</span> #available(iOS <span class="hljs-number">11.0</span>, *) {
    color = <span class="hljs-type">UIColor</span>(named: <span class="hljs-string">"blueColor"</span>)!
} <span class="hljs-keyword">else</span> {
    color = <span class="hljs-type">UIColor</span>(red: <span class="hljs-number">84.0</span>/<span class="hljs-number">255.0</span>, green: <span class="hljs-number">128.0</span>/<span class="hljs-number">255.0</span>, blue: <span class="hljs-number">255.0</span>/<span class="hljs-number">255.0</span>, alpha: <span class="hljs-number">1.0</span>)
}

Create color in Xcode/storyboard use for all projects

We can also create the color in storyboard and use this color in your Xcode for all projects.

Download Demo From here

Related Post

Variables Variables A variable is a named location in memory that is used to hold a value that can be modified by the program. All variable must be declared be...
How to install flutter | Flutter tutorial Flutter is the google’s mobile app SDK for develop the high-quality native app for iOS and android. We can develop the app by use of DART and javascri...
Loop Control Statement Loop control statements are used when a section of code may either be executed a fixed number of times. C gives you a choice of three types of loop st...
Java Operators Java Operators An operator is used to perform an operation over one or more operands. It is a character that represents an action, for example * is a...
Navigation Tab Bar in IOS | Swift tutorial Navigation Tab Bar in IOS | Swift tutorial Different Customizing techniques for Navigation bar with storyboard and code 1) Custom NavigationTabBar b...
Java If-else Statement Java If-else Statement The Java if statement is used to test the condition. It checks boolean condition: true or false. For example, if a number i...

Leave a Reply

Your email address will not be published. Required fields are marked *

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.