iOS进阶之开发常用宏定义
2017-02-20 本文已影响0人
child_cool
#ifndef CommonHeaderFile_h
#define CommonHeaderFile_h
//-------------------获取设备大小-------------------------
/**
* 屏幕大小
* 屏幕宽度
* 屏幕高度
*/
#define SCREEN_BOUNDS [UIScreen mainScreen].bounds
#define SCREEN_WIDTH (SCREEN_BOUNDS.size.width)
#define SCREEN_HEIGHT (SCREEN_BOUNDS.size.height)
// 标准系统状态栏高度
#define SYS_STATUSBAR_HEIGHT 20
// 热点栏高度
#define HOTSPOT_STATUSBAR_HEIGHT 20
// 导航栏(UINavigationController.UINavigationBar)高度
#define NAVIGATIONBAR_HEIGHT 44
// 工具栏(UINavigationController.UIToolbar)高度
#define TOOLBAR_HEIGHT 44
// 标签栏(UITabBarController.UITabBar)高度
#define TABBAR_HEIGHT 44
// APP_STATUSBAR_HEIGHT=SYS_STATUSBAR_HEIGHT+[HOTSPOT_STATUSBAR_HEIGHT]
#define APP_STATUSBAR_HEIGHT (CGRectGetHeight([UIApplication sharedApplication].statusBarFrame))
// 根据APP_STATUSBAR_HEIGHT判断是否存在热点栏
#define IS_HOTSPOT_CONNECTED (APP_STATUSBAR_HEIGHT==(SYS_STATUSBAR_HEIGHT+HOTSPOT_STATUSBAR_HEIGHT)?YES:NO)
// 无热点栏时,标准系统状态栏高度+导航栏高度
#define NORMAL_STATUS_AND_NAV_BAR_HEIGHT (SYS_STATUSBAR_HEIGHT+NAVIGATIONBAR_HEIGHT)
// 实时系统状态栏高度+导航栏高度,如有热点栏,其高度包含在APP_STATUSBAR_HEIGHT中。
#define STATUS_AND_NAV_BAR_HEIGHT (APP_STATUSBAR_HEIGHT+NAVIGATIONBAR_HEIGHT)
/**
* ipone4s大小
* ipone5s大小
* ipone6s大小
* ipone6sPlus大小
* iPad Retina大小
*/
#define IPHONE_4S_SIZE CGSizeMake(640, 960)
#define IPHONE_5S_SIZE CGSizeMake(640, 1136)
#define IPHONE_6S_SIZE CGSizeMake(750, 1334)
#define IPHONE_6SPLUS_SIZE CGSizeMake(1242, 2208)
#define IPAD_RETINA_SIZE CGSizeMake(1536, 2048)
/**
* 是否为某个设备(参数为屏幕的大小)
*/
#define ISDEVICE(DEVICE_SIZE) ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(DEVICE_SIZE, [[UIScreen mainScreen] currentMode].size) : NO)
//-------------------获取设备大小-------------------------
// 是否是iPad
#define ISIPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
//获取系统版本
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
//判断是哪个版本
#define ISVERSION(number) [[UIDevice currentDevice].systemVersion isEqualToString:number]
// 判断是否是哪个版本之后
#define ISVERSIONAFTER(number) [UIDevice currentDevice].systemVersion.floatValue > number
//----------------------图片----------------------------
//读取本地图片
#define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[NSBundle mainBundle]pathForResource:file ofType:ext]
// 获取RGB颜色
#define COLOR(R,G,B,A) [UIColor colorWithRed:R/255.0f green:G/255.0f blue:B/255.0f alpha:A]
// 设置颜色
#define HEXCOLOR(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#define weakify(var) __weak typeof(var) weakSelf = var
//----------------------单例宏定义----------------------------
// .h文件
#define YJSingletonH(name) + (instancetype)shared##name;
// .m文件
#define YJSingletonM(name) \
static id _instance; \
\
+ (instancetype)allocWithZone:(struct _NSZone *)zone \
{ \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
_instance = [super allocWithZone:zone]; \
}); \
return _instance; \
} \
\
+ (instancetype)shared##name \
{ \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
_instance = [[self alloc] init]; \
}); \
return _instance; \
} \
\
- (id)copyWithZone:(NSZone *)zone \
{ \
return _instance; \
}
// ==================================重写NSLog,Debug模式下打印日志和当前行数==========================================================
#if DEBUG
#define NSLog(format, ...) do { \
fprintf(stderr, "<%s : %d> %s\n", \
[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], \
__LINE__, __func__); \
(NSLog)((format), ##__VA_ARGS__); \
fprintf(stderr, "-------\n"); \
} while (0)
#define NSLogRect(rect) NSLog(@"%s x:%.4f, y:%.4f, w:%.4f, h:%.4f", #rect, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)
#define NSLogSize(size) NSLog(@"%s w:%.4f, h:%.4f", #size, size.width, size.height)
#define NSLogPoint(point) NSLog(@"%s x:%.4f, y:%.4f", #point, point.x, point.y)
#else
#define NSLog(FORMAT, ...) nil
#define NSLogRect(rect) nil
#define NSLogSize(size) nil
#define NSLogPoint(point) nil
#endif
#ifdef DEBUG
#define YJString [NSString stringWithFormat:@"%s", __FILE__].lastPathComponent
#define YJLog(...) printf("%s: %s 第%d行: %s\n\n",[[NSString yj_GetCurrentTime] UTF8String], [YJString UTF8String] ,__LINE__, [[NSString stringWithFormat:__VA_ARGS__] UTF8String]);
#else
#define YJLog(...)
#endif
#endif /* CommonHeaderFile_h */