iOS常用宏定义

//获取AppDelegate
#define ShareApp ((AppDelegate *)[[UIApplication sharedApplication] delegate])


//16进制颜色转RGB
//For example: self.view.backgroundColor = UIColorFromRGBA(0xfdf4e1, 1);
#define UIColorFromRGBA(rgbValue, alphaValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0x00FF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0x0000FF))/255.0 \
alpha:alphaValue]


//本地保存常用位置(沙盒目录下的Library/Caches 文件夹,可以修改代码替换其他目录)
#define CACHESPATH [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]

//获取APP版本号
#define KApp_Version [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

//获取构建版本号
#define KBuild_Version [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]


//Release版本用来屏蔽Log日志, 平时为被注释状态
#if DEBUG
#warning NSLogs will be shown
#else
#define NSLog(...) {}
#endif

//检测程序是在真机上还是在模拟器上
#if TARGET_IPHONE_SIMULATOR
#define SIMULATOR 1
#elif TARGET_OS_IPHONE
#define SIMULATOR 0
#endif


//weakSelf
#define XTWeakSelf __weak typeof(self) weakSelf = self;

//屏幕宽高
#define SCREEN_WIDTH [UIScreen  mainScreen].bounds.size.width
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

//不管横竖屏都获取较短的那个长度
#define AUTO_SCREEN_WIDTH (([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height)?[UIScreen mainScreen].bounds.size.height:[UIScreen mainScreen].bounds.size.width)

//如果是PLUS 就获取PLUS的宽度 否则获取6S的宽度
#define ADAPTIVE_WIDTH ((AUTO_SCREEN_WIDTH > 375.0) ? AUTO_SCREEN_WIDTH : 375.0)

//自适应长度 (PLUS 或者 非PLUS)
#define ADAPTIVE_SIZE(value) (((value)/375.0) * ADAPTIVE_WIDTH)


//自适应尺寸(以6s尺寸为基准,例如参数中的value值为10 在6s上为10 在Plus上为value/375*Plus的屏幕宽度,此外这个尺寸只以屏幕宽度为准,就算横屏状态下横竖颠倒,依然以短的尺寸为宽度)
#define AUTO_375SIZE(value) (((value)/375.0) * (([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height)?[UIScreen mainScreen].bounds.size.height:[UIScreen mainScreen].bounds.size.width))


//根据分辨率判断机型
#define isPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
#define isPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define isPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)
#define isPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242,2208), [[UIScreen mainScreen] currentMode].size) : NO)
#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

#pragma mark ---------------------系统相关--------------------

//获取系统版本
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]
#define isIOS7 ([[[UIDevice currentDevice] systemVersion] intValue]==7)
#define isIOS8 ([[[UIDevice currentDevice] systemVersion] intValue]==8)
#define isIOS9 ([[[UIDevice currentDevice] systemVersion] intValue]==9)
#define isIOS10 ([[[UIDevice currentDevice] systemVersion] intValue]==10)
#define isAfterIOS7 ([[[UIDevice currentDevice] systemVersion] intValue]>7)
#define isAfterIOS8 ([[[UIDevice currentDevice] systemVersion] intValue]>8)
#define isAfterIOS9 ([[[UIDevice currentDevice] systemVersion] intValue]>9)
#define isAfterIOS10 ([[[UIDevice currentDevice] systemVersion] intValue]>10)

//弃用的方法后缀
#define TEMPORARILY_ABANDONED __attribute__((deprecated))

//系统控件默认高度
#define kStatusBarHeight        (20.f)

#define kTopBarHeight           (44.f)
#define kBottomBarHeight        (49.f)

#define kCellDefaultHeight      (44.f)

#define kEnglishKeyboardHeight  (216.f)
#define kChineseKeyboardHeight  (252.f)

你可能感兴趣的:(iOS)