常用宏

//屏幕宽度:#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

推荐阅读更多精彩内容

  • iOS开发过程中,使用的一些常用宏定义 字符串是否为空#define kStringIsEmpty(str) ([...
    goyohol阅读 5,007评论 29 84
  • ifndef MacroDefinition_h define MacroDefinition_h //-----...
    灰客阅读 192评论 0 0
  • //AppDelegate #define APPDELEGATE [(AppDelegate*)[UIAppli...
    __life__阅读 117评论 1 0
  • 思之,念之 却不可及 文字,是唯一 能够触摸到你的方式 春雨 细碎而又柔软 渗透着一丝清凉 柔软的柳条 吐出一簇簇...
    游游茶舍阅读 214评论 0 1
  • 至今高考后两个多月过去了在这个两个多月时间里同学们都纷纷周游全国在空间朋友圈晒着精美无比的照片又有同学找到兼职可以...
    清悦橙阅读 447评论 3 1
  • 1. 时光荏苒,一晃眼就大四了。成了纯正的老学姐,回想自己这几年,也不明白自己做了啥,为了啥! 记得一句话:“慢下...
    彼岸非凡阅读 478评论 5 3