设备
// 横屏
#define UI_IS_LANDSCAPE ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight)
// iPad
#define UI_IS_IPAD ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
// iPhone
#define UI_IS_IPHONE ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
#define UI_IS_IPHONE5 (UI_IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0)
#define UI_IS_IPHONE6 (UI_IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 667.0)
#define UI_IS_IPHONE_PLUS (UI_IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 736.0 || [[UIScreen mainScreen] bounds].size.width == 736.0) // Both orientations
#define UI_IS_IPHONE_X (UI_IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 812.0)
// 屏幕尺寸
#define SCREEN_W [UIScreen mainScreen].bounds.size.width
#define SCREEN_H [UIScreen mainScreen].bounds.size.height
系统
#define IsIOS6Later ([[[UIDevice currentDevice] systemVersion] floatValue] >=6.0 ? YES : NO)
#define IsIOS7Later ([[[UIDevice currentDevice] systemVersion] floatValue] >=7.0 ? YES : NO)
#define IsIOS8Later ([[[UIDevice currentDevice] systemVersion] floatValue] >=8.0 ? YES : NO)
#define SUPPORT_IPHONE_OS_VERSION(version) ( __IPHONE_OS_VERSION_MIN_REQUIRED <= version && __IPHONE_OS_VERSION_MAX_ALLOWED >= version)
#define UserDefaults [NSUserDefaults standardUserDefaults]
#define NotificationCenter [NSNotificationCenter defaultCenter]
设置Debug模式下打印log,release模式下不打印
#ifdef DEBUG
# define DebugLog(format, ...) NSLog((@"[DEBUG]%s " format), __PRETTY_FUNCTION__, ##__VA_ARGS__);
#else
# define DebugLog(...)
# define NSLog(...)
#endif
颜色
//
#define RGBA(r,g,b,a) [UIColor colorWithRed:(float)r/255.0f green:(float)g/255.0f blue:(float)b/255.0f alpha:a]
#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:r green:g blue:b alpha:a]
#define HSVACOLOR(h,s,v,a) [UIColor colorWithHue:h saturation:s value:v alpha:a]
#define MAIN_GREY [UIColor colorWithRed:0.55 green:0.55 blue:0.56 alpha:1.00]
#define MAIN_GRAY HEXCOLOR(0x999999)
#define BACK_GREY HEXCOLOR(0xefefef)
字体大小(常规/粗体)
#define BOLDSYSTEMFONT(FONTSIZE) [UIFont boldSystemFontOfSize:FONTSIZE]
#define SYSTEMFONT(FONTSIZE) [UIFont systemFontOfSize:FONTSIZE]
#define FONT(NAME, FONTSIZE) [UIFont fontWithName:(NAME) size:(FONTSIZE)]
常用方法
// 设置frame
#define RectMake(x,y,w,h) CGRectMake(x,y,w,h)
// Max Y
#define GetViewMaxY(view) CGRectGetMaxY((view).frame)
单例
#ifndef SINGLETON_GCD
#define SINGLETON_GCD(classname) \
\
+ (classname *)sharedInstance##classname { \
\
static dispatch_once_t oncePredicate; \
static classname * sharedInstance##classname = nil;\
dispatch_once( &oncePredicate, ^{ \
sharedInstance##classname = [[self alloc] init]; \
}); \
\
return sharedInstance##classname; \
}
#endif
网友评论