Search code examples
objective-cswiftassetsxcode9uicolor

How to get color from Assets.xcassets?


I've created Color Set in Assets.xcassets, you can see it in screenshot below

enter image description here

And my question is

How to get this color in code ?


Solution

  • You should use this init of UIColor

    init?(named name: String) 
    

    For example:

    view.backgroundColor = UIColor(named: "Greeny")
    

    And your name of Color in Assets must be the same as parameter in init