![handle custom uicolors in ios](https://www.remotepanda.com/wp-content/uploads/2018/02/handle-custom-uicolors-in-ios-Banner-Images.jpg 800w)
Handle custom UIColors in iOS
If you’re an App developer then you definitely faced some challenges while dealing with multiple color codes that you’ve to use in your more than one apps.
If we want to set the color to some UIView than we’ll do it on storyboard via attributed inspector or we’ll use one of the following approaches with UIColor class programmatically:
-
init(white: CGFloat, alpha: CGFloat)
-
init(hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat)
-
init(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat)
-
init(CGColor cgColor: CGColor!)
-
init(patternImage image: UIImage)
-
init(CIColor ciColor: CIColor)
This seems to be boring while we have to set it by giving proper values, for example :
self.view.backgroundColor = UIColor(red: 120/255, green: 150/255, blue: 200/255, alpha: 1)
Let’s see step by step how we can implement this :
You need to add “New Color set” in your assets file.
![You need to add “New Color set” in your assets file.](https://www.remotepanda.com/wp-content/uploads/2018/02/1_MRsIqfOb-yjFhsxluZeh4w-800x500-1.png 800w)
Give proper naming convention to your Color Set:
![Give proper naming convention to your Color Set](https://www.remotepanda.com/wp-content/uploads/2018/02/1_q4XyrZpsaE6Io8GF3jDFBw-800x500-1.png 800w)
Select a color set and assign required color through attributed inspector.
![Give proper naming convention to your Color Set](https://www.remotepanda.com/wp-content/uploads/2018/02/1_uBDt5V187Hs4wZS0BpVOhA-800x500-1.png 800w)
![Give proper naming convention to your Color Set](https://www.remotepanda.com/wp-content/uploads/2018/02/1_sxyhvRes2lYnkuILVLHsnw-800x500-1.png 800w)
Add all required custom colors by creating color sets.
![Add all required custom colors by creating color sets.](https://www.remotepanda.com/wp-content/uploads/2018/02/1_kWeqxk9kKQhykopoAScR4g-800x500-1.png 800w)
Now it’s time to use this Custom colors into our app. First, we’ll see how we can set colors to UIView via a storyboard.
![](https://www.remotepanda.com/wp-content/uploads/2018/02/1_p9AZzzIprO06d3DRGxaPkw-800x500-1.png 800w)
Conclusion:
Alright, guys, those are some tips for using the colors properly in iOS. Hopefully next time I’ll come up with some other feature.