iOS macro

Yesterday , I was fixing the Sar for iPhone 5. iPhone 4s and iPhone 5 are just change the height. For landscape , iPhone 4 is 480 and iPhone 5 is 568. So, Myanmar Keyboard have a problem with iPhone 5 in landscape mode. it couldn’t show full.

I need to change width in landscape mode. I don’t want to put so many condition on all of code for landscape mode. I already declare width , height , x , y , padding in marco value.


#define L_START_X 3
#define L_WIDTH 44

If it’s iphone 5 , i just need to change the #define value. Simple. So, I need to put condition in #define.

First I create the the marco in .pch file like following.

#define isIphone ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)

#define isIphone5 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [[UIScreen mainScreen] bounds].size.height > 480)

After that I change L_START_X and L_WIDTH like following.

#define L_START_X (isIphone5 ? 15:3)
#define L_WIDTH (isIphone5 ? 50:44)

So, I don’t need to write extra code for iPhone 5. Just change in marco. Simple ? Yes, it’s very simple to update for iPhone 5 if you are using macro value for static value.

comments powered byDisqus