How can we use Assets Catalog Color Sets?

后端 未结 9 1540
遇见更好的自我
遇见更好的自我 2020-11-29 06:57

I usually use custom UIColors on iOS using extensions with Swift, but now with iOS 11/ Xcode 9 we can create Colors Sets. How can we use them?

Update - Tip

9条回答
  •  悲&欢浪女
    2020-11-29 07:37

    (short answer to the question update: there is UIColor(named: "MyColor") in Xcode 9.0)

    Answering the original question:

    1. you create your color set

    1. you find your color among your snippets and you drag-n-drop it

    1. it will translate to a color literal when looking at the source code:

      #colorLiteral(red: 0, green: 0.6378085017, blue: 0.8846047521, alpha: 1)

    You notice how the values of red, green and blue are different? It's because I defined them using Color Space Display P3, but the colorLiteral is using Color Space sRGB.

提交回复
热议问题