3

I am developing an ipad app which will have two targets but color theme will be different for the targets e.g. in Target1 the selected button font color will be red and in Target2 the selected button font color will be green.I was wondering that is this feasible in interface builder itself?

Thanks in advance!!

Desert Rose
  • 3,376
  • 1
  • 30
  • 36

2 Answers2

2

You can use preprocessor macros. Select your target, go to Build Settings section of the target, find Preprocessor Marcro and add new macro for each target (for example Target1 for your first target and Target2 for your second target). Now you can use code:

#ifdef Target1
  //code for your first target
#elif Target2
  //code for your second target
#endif

I hope it will help you ;-)

Alien
  • 576
  • 1
  • 4
  • 16
  • If I have hundreds of targets then this is not scalable. Is there any other elegant solution? – A_G Jan 09 '18 at 06:50
0

You can use this solution:

Create single .h file and multiple .m files for multiple targets.

  1. create .h file with Theme of your app

//h file

@interface AppTheme : NSObject 


@property (nonatomic) UIColor *backgroundColor;
@property (nonatomic) UIColor *buttonTextColor;
//and so on.
//you can create classes or protocols for curtain elements of your app
//
@property (nonatomic) ButtonStyle *defaultButtonStyle;
@property (nonatomic) ButtonStyle *destroyButtonStyle;
//and so on where 
// Button style has titleColor, titleFont, background and ect.

@end
  1. Now you can create .m file for target A

AppTheme+A.m where you can define your Theme like this:

@implementation

- (instancetype)init {

   if (self = [super init]){
       self.backgroundColor = [UIColor black];
       self.buttonTextColor = [UIColor white];
//and so on
   }

   return self;
}

@end

for the target B you can create other file: AppTheme+B.m where you can define your Theme like this:

@implementation

- (instancetype)init {

   if (self = [super init]){
       self.backgroundColor = [UIColor pinkColor];
       self.buttonTextColor = [UIColor yellowColor];
//and so on
   }

   return self;
}

@end
  1. Then include your AppTheme+A.m in target A and AppTheme+B.m target B.
Nikolay Shubenkov
  • 3,133
  • 1
  • 29
  • 31