Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set color (or other properties) of UIView in xib file PER TARGET

I am working on a few different apps that reuse the same xib file, but each app has it's own color scheme.

For most parts of the app (Nav bar color, UIBarButtonItem's), we use the UIAppearance method for each app.

For some parts, however, it becomes more complicated, such as the color of a labels need to be color A, B, and C for App 1, and need to be Color B, C, and D for App 2, and I cannot think of an easy way of doing this with UIAppearance.

An obvious, hard way of doing this would be somewhere when the view controller loads to set the colors of the label there, and have the colors stored in a plist or something similar. Also I could duplicate the xib for each project and edit the colors in the xib, but it defeats the purpose of sharing the xibs and I would have to be constantly updating multiple xibs for each change to the UI.

I am curious, however, if I could use the "User Defined Runtime Attributes" or something else that will be easy to manager in order to tackle this problem?

Thanks in advance!

like image 351
Will Avatar asked Nov 28 '25 10:11

Will


1 Answers

Make two Targets named

redColor blueColor

in both of it , Goto Build Settings > set Pre Processor macros >

for redColor > add Preprocessor Macro IS_RED_THEME for blueColor> add Preprocessor Macro IS_BLUE_THEME

Now in your Class

in viewWillAppear or in viewDidLoad or anywhere you want put this code :

#ifdef IS_RED_THEME
//apply Red COlor
#elif IS_BLUE_THEME
//apply Blue Color
#endIf 
like image 149
Zeeshan Avatar answered Nov 30 '25 23:11

Zeeshan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!