常用宏

//屏幕宽度:#define kSCREENWIDTH   [[UIScreen mainScreen] bounds].size.width

//屏幕高度:#define kSCREENHEIGHT   [[UIScreen mainScreen] bounds].size.height

//屏幕尺寸:#define WINSIZE [[UIScreen mainScreen] bounds].size

程序更新:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"程序地址"]]

//图片名获取图片:#define IMG(name) [UIImage imageNamed:name]

//获取系统版本

#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]

#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]

#define isIOS4 ([[[UIDevice currentDevice] systemVersion] intValue]==4)

#define isIOS5 ([[[UIDevice currentDevice] systemVersion] intValue]==5)

#define isIOS6 ([[[UIDevice currentDevice] systemVersion] intValue]==6)

#define isIOS7 ([[[UIDevice currentDevice] systemVersion] intValue]==7)

#define isIOS8 ([[[UIDevice currentDevice] systemVersion] intValue]==8)

#define isIOS9 ([[[UIDevice currentDevice] systemVersion] intValue]==9)

#define isIOS10 ([[[UIDevice currentDevice] systemVersion] intValue]==10)

#define isAfterIOS4 ([[[UIDevice currentDevice] systemVersion] intValue]>4)

#define isAfterIOS5 ([[[UIDevice currentDevice] systemVersion] intValue]>5)

#define isAfterIOS6 ([[[UIDevice currentDevice] systemVersion] intValue]>6)

#define isAfterIOS7 ([[[UIDevice currentDevice] systemVersion] intValue]>7)

#define isAfterIOS8 ([[[UIDevice currentDevice] systemVersion] intValue]>8)

本地地址:#define UserInfoFilePath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject] stringByAppendingPathComponent:@"本地文件名"]

//-------------------打印日志-------------------------

//DEBUG  模式下打印日志,当前行

#ifdef DEBUG

#   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

#else

#   define DLog(...)

#endif

//重写NSLog,Debug模式下打印日志和当前行数

#if DEBUG

#define NSLog(FORMAT, ...) fprintf(stderr,"\\nfunction:%s line:%d content:%s\\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);

#else

#define NSLog(FORMAT, ...) nil

#endif

//获取系统版本

#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]

#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]

//判断是真机还是模拟器

#if TARGET_OS_IPHONE

//iPhone Device

#endif

#if TARGET_IPHONE_SIMULATOR

//iPhone Simulator

#endif

//读取本地图片

#define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]

//定义UIImage对象

#define IMAGE(A) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:A ofType:nil]]

//----------------------颜色类---------------------------

// rgb颜色转换(16进制->10进制)

#define UIColorFromRGB(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]

//带有RGBA的颜色设置

#define COLOR(R, G, B, A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]

// 获取RGB颜色

#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]

#define RGB(r,g,b) RGBA(r,g,b,1.0f)

//背景色

#define BACKGROUND_COLOR [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0]

//清除背景色

#define CLEARCOLOR [UIColor clearColor]

//定义一个API

#define APIURL                @"http://xxxxx/"

//登陆API

#define APILogin              [APIURL stringByAppendingString:@"Login"]

//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)

//NSUserDefaults 实例化

#define USER_DEFAULT [NSUserDefaults standardUserDefaults]

//单例化一个类

#define SYNTHESIZE_SINGLETON_FOR_CLASS(classname) \\

\\

static classname *shared##classname = nil; \\

\\

+ (classname *)shared##classname \\

{ \\

@synchronized(self) \\

{ \\

if (shared##classname == nil) \\

{ \\

shared##classname = [[self alloc] init]; \\

} \\

} \\

\\

return shared##classname; \\

} \\

\\

+ (id)allocWithZone:(NSZone *)zone \\

{ \\

@synchronized(self) \\

{ \\

if (shared##classname == nil) \\

{ \\

shared##classname = [super allocWithZone:zone]; \\

return shared##classname; \\

} \\

} \\

\\

return nil; \\

} \\

\\

- (id)copyWithZone:(NSZone *)zone \\

{ \\

return self; \\

}

#endif

你可能感兴趣的:(常用宏)