2023年7月14日发(作者:)
OC常⽤宏定义测试输出 Log#pragma mark - DEBUG#ifdef DEBUG// 定义是输出Log#define DLog(format, ...) NSLog(@"Line[%d] %s " format, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__)#else// 定义是输出Log#define DLog(format, ...)#endif// 只输出类名#define LogClassName DLog(@"")屏幕相关#pragma mark - 屏幕#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].siz#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].s#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].s#define iPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentM#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)#define isPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)#define kScreenHeight [[UIScreen mainScreen] bounds].#define kScreenWidth [[UIScreen mainScreen] bounds].#define kStatusBarHeight 20#define kNavigationBarHeight 44#define kNavigationBarIcon 20#define kTabBarHeight 49#define kTabBarIcon 30系统相关#pragma mark - 系统相关// 检查系统版本#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscend#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescendin// 获取版本
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]//获取当前语⾔
#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])//判断是真机还是模拟器
#if TARGET_OS_IPHONE
//iPhone Device
#endif
#if TARGET_IPHONE_SIMULATOR
//iPhone Simulator
#endif//使⽤ARC和不使⽤ARC
#if __has_feature(objc_arc)
//compiling with ARC
#else
// compiling without ARC
#endif定义弱引⽤、强引⽤#define WeakSelf(weakSelf) __weak __typeof(&*self)weakSelf = self#define ESWeak(var, weakVar) __weak __typeof(&*var) weakVar = var#define ESStrong_DoNotCheckNil(weakVar, _var) __typeof(&*weakVar) _var = weakVar#define ESStrong(weakVar, _var) ESStrong_DoNotCheckNil(weakVar, _var); if (!_var) return;#define ESWeak_(var) ESWeak(var, weak_##var);#define ESStrong_(var) ESStrong(weak_##var, _##var);/** defines a weak `self` named `weakSelf` */#define ESWeakSelf ESWeak(self, weakSelf);/** defines a strong `self` named `strongSelf` from `weakSelf` */#define ESStrongSelf ESStrong(weakSelf, strongSelf);定义警告宏#define SuppressPerformSelectorLeakWarning(Stuff) do { _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored "-Warc-performSelector-leaks"") Stuff; _Pragma("clang diagnostic pop") } while (0)颜⾊宏// 随机颜⾊#define RANDOM_COLOR [UIColor colorWithRed:arc4random_uniform(256) / 255.0 green:arc4random_uniform(256) / 255.0 blue:arc4random_uniform(256) / 255.0 alpha:1// rgb颜⾊转换(16进制->10进制)
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbVal#define RGBACOLOR(r, g, b, a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]#define RGBCOLOR(r, g, b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1.0f]
//#define RGBCOLOR(r, g, b) RGBACOLOR(r, g, b, 1.0f)
其他宏//G-C-D
#define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define MAIN(block) dispatch_async(dispatch_get_main_queue(), block)//由⾓度获取弧度 有弧度获取⾓度
#define degreesToRadian(x) (M_PI * (x) / 180.0)
#define radianToDegrees(radian) (radian*180.0)/(M_PI)// 引⽤:/p/7c3ee5e67d03// 检测block是否可⽤#define BLOCK_EXEC(block, ...) if (block) { block(__VA_ARGS__); }// 宏定义之前的⽤法if (completionBlock) {
completionBlock(arg1, arg2);
}
// 宏定义之后的⽤法BLOCK_EXEC(completionBlock, arg1, arg2);
发布者:admin,转转请注明出处:http://www.yc00.com/news/1689264856a226441.html
评论列表(0条)