Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get color from Assets.xcassets? [duplicate]

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 ?

like image 917
Tikhonov Aleksandr Avatar asked Sep 13 '17 16:09

Tikhonov Aleksandr


People also ask

How do I make assets Xcassets?

Create a new file (⌘N) and select the Asset Catalog template in the iOS – Resource panel. Choose a name, select the targets that should include the catalog, and click “Create.” Select the new *. xcassets file in the project explorer.


1 Answers

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

like image 81
Tikhonov Aleksandr Avatar answered Sep 20 '22 05:09

Tikhonov Aleksandr