iosxcodecolorspalette

How to define a color scheme in Xcode


I'd like to define a color scheme for my iOS project, in a way that it's easy to replace some colors. Let's say I have a "main" color and a "secondary" color, used in many elements in my app, and in a future I maybe want to set the "main" color to any other value that the one it currently has.

So far I've been using a custom UIColor category to define and use my colors in code, and creating a palette with the same colors for using it in IB and Storyboards.

This way, replacing colors in code is far straightforward, but doing it in IB and Storyboard is so painful... I didn't find an easy way to find/replace colors.

Any idea on how can I manage to do that? I'm open to any suggestion. Thank you in advance

EDIT 1: Maybe it's not clear enough in the question. I'd like to create a scheme such as I can use it both in code and in IB, but defining the colors only once, and being able to switch colors in a way that colors referenced both in code and in IB change accordingly.


Solution

  • An easy way i can do that in Swift:

    Finally depending on the scheme chosen, some colors or others will be drawn.

    Another way that I have found is next link:

    Protocol-Oriented Themes for iOS Apps