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

Array An array is a collection of similar kind of data elements stored in adjacent memory locations and are referred to by a single array-name. The first el...
UIPopOverPresentationController In Swift UIPopOverPresentationController UIPopOverViewController in swift is writen in swift 3.1 and Use the xcode Version 8.3.2. For use this import the Pop...
Custom View by use of xib in swift Custom View by use of xib in swift We can create the custom and common view by the use xib in swift 3.1 and xcode 8.3.2 . Custom views are common and...
Break Statement in JAVA Break Statement in JAVA The break statement is usually used in following two scenarios: The break statement terminates the loop immediately, and...
C Language – Introduction Why C? There are three important aspects of any language so as C has : The way it stores data, The way it operates on this data and How th...
Data Types in Java Data Types in Java Data types represent the different values to be stored in the variable, for example if a variable has int data type, it ...

Leave a Reply

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