I have a project that I need to change overall color themes in the app. A lot of my UI elements are built through Interface Builder in Xcode 6.1. I need to set colors as variables in interface builder, so if I set a preprocessor telling the app to use a certain scheme then the colors will change in interface builder. Is this even possible?
To use the color picker in Xcode, you can access it in two ways: Go to the Xcode's toolbar and click Edit -> Format -> Show Colors.
Suggested approach: In the old days values outside of 0 and 1 would be clamped (i.e., forced to 0 or 1) because they didn't mean anything, but wide color support means that is no longer the case – a red value beyond 1.0 is especially red, going into the Display P3 gamut.
I'm not aware of any way to do this with interface builder, however there is a way that you can set appearance properties in code for many IOS UI elements that will then apply globally. As an example see the following snippet of code:
UIToolbar.appearance().tintColor = UIColor.whiteColor()
UIToolbar.appearance().barTintColor = UIColor.blackColor()
UITableView.appearance().separatorColor = UIColor.grayColor()
UITableView.appearance().sectionIndexColor = UIColor.grayColor();
UINavigationBar.appearance().tintColor = UIColor.blueColor()
UINavigationBar.appearance().barTintColor = UIColor.blackColor()
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]
The code sets a the default tint and bar color for all the UIToolbars, separator and section index colors for all UITableViews, and appearance properties for all the UINavigation views in my app..
You could use #if
to set the appearance differently depending on the environment variables set in the compiler.
If you want to find out more about how this works Id suggest reading Apples documentation on UIAppearance properties here: UIAppearance Documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With