ios常用的小宏宏

2018-05-23  本文已影响0人  傻啦啦了

写点常用的宏,有什么需要补充的给我留言哦

#define iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
 
#define iPhoneXR ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) : NO)
 
#define iPhoneXS_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) : NO)
#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 kYYZVersion      [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

小版本号  就是build号
#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 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 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 UIFONTSIZE(font) [UIFont systemFontOfSize:font]
// 创建alloc
#define ALLOC(view) [[view alloc] init]
// NSUserDefaults
#define UserDefaults [NSUserDefaults standardUserDefaults]
// UIApplication
#define UIAPPLICATION [UIApplication sharedApplication]
// window
#define WINDOW [[UIAPPLICATION delegate] window]
#define EMPTY_STRING(string) \
([string isKindOfClass:[NSNull class]] || \
string == nil || [string isEqualToString:@""])

#define returnCondition(condition)    if (condition) {return;}
#define LazyGetMethod(type, attribute)            \
- (type *)attribute                                 \
{                                                   \
if (!_##attribute) {                            \
_##attribute = [[type alloc] init];         \
}                                               \
return _##attribute;                            \
}
上一篇下一篇

猜你喜欢

热点阅读