iOS常用的宏

2018-01-12  本文已影响19人  Demonboy
#ifndef weakify
#if __has_feature(objc_arc)
#define weakify( x )    autoreleasepool{} __weak __typeof__(x) __weak_##x##__ = x;
#else
#define weakify( x )    autoreleasepool{} __block __typeof__(x) __block_##x##__ = x;
#endif
#endif

#ifndef normalize
#if __has_feature(objc_arc)
#define normalize( x )    try{} @finally{} __typeof__(x) x = __weak_##x##__;
#else
#define normalize( x )    try{} @finally{} __typeof__(x) x = __block_##x##__;
#endif
#endif

#define SystemVersionNow [[UIDevice currentDevice].systemVersion floatValue]
// 版本
#define IsAtLeastiOSVersion(X) ([[[UIDevice currentDevice] systemVersion] compare:X options:NSNumericSearch] != NSOrderedAscending)

// 界面
// 状态栏的高度
#define kStatusHeight [[UIApplication sharedApplication] statusBarFrame].size.height
// 导航栏的高度
#define naviHeight 44.0
// 状态栏 + 导航栏 的高度
#define kNavHeight  (kStatusHeight + naviHeight)
// tabbar的高度
#define kTarBarHeight YDMainTabbarVC.tabBar.frame.size.height
// 指示器的高度
#define kiPhoneXIndicatorHeight (iPhoneX ? 34.0 : 0)

#define kYYZVersion      [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
#define kYYZInnerVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]

#define iPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ?            CGSizeEqualToSize(CGSizeMake(640,960), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640,1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(750,1334), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(640,1136), [[UIScreen mainScreen] currentMode].size)) : NO)
#define iPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(1125,2001), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(1242,2208), [[UIScreen mainScreen] currentMode].size)) : NO)
#define iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ?            CGSizeEqualToSize(CGSizeMake(1125,2436), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone45Pad (iPhone4||iPhone5||IsiPad)
#define IsiPad      ([[UIDevice currentDevice].model rangeOfString:@"iPad"].location != NSNotFound)
#define isPad       (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

#define kScreen      ([[UIScreen mainScreen] bounds])
#define kScreenH     ([[UIScreen mainScreen]bounds].size.height)
#define kScreenW     ([[UIScreen mainScreen]bounds].size.width)

// 新的适配比例
#define FONT_RATIO(a)  ((((int)ScreenW == 320 || isPad) ? (320.0 / 375) : (((int)ScreenW == 375) ? 1.0 : (414.0 / 375))) * (a))
#define SCREEN_RATIO_CEIL(a)  (ceil((((int)ScreenW == 320 || isPad) ? (320.0 / 375) : (((int)ScreenW == 375) ? 1.0 : (414.0 / 375))) * (a) ))//向上取整
#define HEIGHT_RATIO_CEIL(a) (ceil(SCREEN_RATIO_CEIL(a) * ((iPhone4 || isPad || IsiPad) ? (480.0 / 568.0): 1.0)))
#define HEIGHT_RATIO  (((int)ScreenH == 480 || (int)ScreenH == 568 || isPad) ? (568.0 / 667) : (((int)ScreenH == 667 || (int)ScreenH == 812 ) ? 1.0 : (736.0 / 667)))
上一篇下一篇

猜你喜欢

热点阅读