ios中常用的宏定义

/**获取屏幕宽度与高度 导航,tabbar高度*/

#define SCREEN_WIDTH   [UIScreen mainScreen].bounds.size.width


#define SCREEN_HEIGHT  [UIScreen mainScreen].bounds.size.height

#define NavBarHeight                        self.navigationController.navigationBar.bounds.size.height

#define TabBarHeight                        self.tabBarController.tabBar.bounds.size.height

#define ViewWidth(v)                        v.frame.size.width

#define ViewHeight(v)                      v.frame.size.height

#define ViewX(v)                            v.frame.origin.x

#define ViewY(v)                            v.frame.origin.y

/**获取通知中心*/

#define ZSNotificationCenter  [NSNotificationCenter defaultCenter]

/**颜色*/

#define ZSRandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]//随机色

#define ZSRGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]//rgb

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

#define ZSlearColor [UIColor clearColor]//透明色

#define zsColorNavBG [UIColor colorWithHexString:@"0xF8F8F8"]

#define zsColorNavTitle [UIColor colorWithHexString:@"0x323A45"]

#define zsColorTableBG [UIColor colorWithHexString:@"0xFFFFFF"]

#define zsColorTableSectionBg [UIColor colorWithHexString:@"0xF2F4F6"]

#define zsColor222 [UIColor colorWithHexString:@"0x222222"]

#define zsColor666 [UIColor colorWithHexString:@"0x666666"]

#define zsColor999 [UIColor colorWithHexString:@"0x999999"]

#define zsColorDDD [UIColor colorWithHexString:@"0xDDDDDD"]

#define zsColorCCC [UIColor colorWithHexString:@"0xCCCCCC"]

#define zsColorBrandGreen [UIColor colorWithHexString:@"0x3BBD79"]

#define zsColorBrandRed [UIColor colorWithHexString:@"0xFF5846"]

#define YAXMainColor [UIColor colorWithHexString:@"0x29B2BB"] //主题色

//#define YAXMainColor ZSRGBColor(225, 53, 58) //主题色

#define YAXBacColor ZSRGBColor(240, 240, 240) //背景灰色

#define YAXGreen ZSRGBColor(105,176,45)//绿色

#define width(a) (SCREEN_WIDTH/375)*a

#define height(a) (SCREEN_HEIGHT/667)*a

#define YAXButton_HEIGHT 44

#define YAXMAIGN 15

#define YAXHMAIGN width(20)

#define YAXSMAIGN height(20)

#define YAXLMAGIN 10

#define YAXPaddingLeftW width(15)

#define ZSStrFormat(a,b) [NSString stringWithFormat:@"%@%@",a,b]

#define FONT(F) [UIFont systemFontOfSize:F]

#define  zsBackButtonFontSize FONT(16) //字体

#define  zsNavTitleFontSize FONT(18)

#define  zsTitieFontSize FONT(14)

#define  zsTipFont FONT(15)

//圆角view

#define CORNERRADIUS(view,radiu) \

view.layer.cornerRadius = radiu;\

view.layer.masksToBounds = YES;\

//默认图片

#define IMAGE_PLACEHOLDER [UIImage imageNamed:@"loadImage"]

#define NavMAXY CGRectGetMaxY(self.navigationController.navigationBar.frame)

#define TabBarY self.tabBarController.tabBar.y

/**Log*/

#ifdef DEBUG

#define DLog(fmt, ...) NSLog((@"[文件名:%s]\n" "[函数名:%s]\n" "[行号:%d] \n" fmt), __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__);

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

#define NSLog(...) NSLog(__VA_ARGS__);

#define MyNSLog(FORMAT, ...) fprintf(stderr,"[%s]:[line %d行] %s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);

#else

#define DLog(...)

#define DeBugLog(...)

#define NSLog(...)

#define MyNSLog(FORMAT, ...)

#endif

/**强弱引用    http://cc.cocimg.com/api/uploads/20160712/1468319802739618.png*/

#define ZSWeakSelf(type)  __weak typeof(type) weak##type = type;  //弱

#define ZSStrongSelf(type)  __strong typeof(type) type = weak##type;  //强

/**view边框*/

#define ZSViewBorderRadius(View, Radius, Width, Color)\

\

[View.layer setCornerRadius:(Radius)];\

[View.layer setMasksToBounds:YES];\

[View.layer setBorderWidth:(Width)];\

[View.layer setBorderColor:[Color CGColor]]

/**alertView*/

#define zsTipAlert(_S_, ...)    [[[UIAlertView alloc] initWithTitle:@"提示" message:[NSString stringWithFormat:(_S_), ##__VA_ARGS__] delegate:nil cancelButtonTitle:@"知道了" otherButtonTitles:nil] show]

/**判断当前的iPhone设备/系统版本*/

#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)//判断是否为iPhone

#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)//判断是否为iPad

#define IS_IPOD ([[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"]) //判断是否为ipod

#define iPhone5SE [[UIScreen mainScreen] bounds].size.width == 320.0f && [[UIScreen mainScreen] bounds].size.height == 568.0f// 判断是否为 iPhone 5SE

#define iPhone6_6s_7 [[UIScreen mainScreen] bounds].size.width == 375.0f && [[UIScreen mainScreen] bounds].size.height == 667.0f// 判断是否为iPhone 6/6s/7

#define iPhone6Plus_6sPlus_7Plus [[UIScreen mainScreen] bounds].size.width == 414.0f && [[UIScreen mainScreen] bounds].size.height == 736.0f// 判断是否为iPhone 6Plus/6sPlus/7Plus

#define IOS_SYSTEM_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]//获取系统版本

#define IOS_VERSION_8_OR_LATER (([[[UIDevice currentDevice] systemVersion] floatValue] >=8.0)? (YES):(NO))//判断 iOS 8 或更高的系统版本

#define kDevice_Is_iPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)

#define kDevice_Is_iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

#define kDevice_Is_iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)

#define kDevice_Is_iPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)

#define kScaleFrom_iPhone5_Desgin(_X_) (_X_ * (SCREEN_WIDTH/320))

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

#if TARGET_OS_IPHONE//iPhone Device

#endif

#if TARGET_IPHONE_SIMULATOR//iPhone Simulator

#endif

//    主要单例

#define UserDefaults                        [NSUserDefaults standardUserDefaults]

#define NotificationCenter                  [NSNotificationCenter defaultCenter]

#define SharedApplication                  [UIApplication sharedApplication]

#define Bundle                              [NSBundle mainBundle]

#define MainScreen                          [UIScreen mainScreen]

/**沙盒目录文件*/

#define PathTemp NSTemporaryDirectory()//获取temp

#define PathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]//获取沙盒 Document

#define PathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]//获取沙盒 Cache

/**GCD 的宏定义*/

#define ZSDISPATCH_ONCE_BLOCK(onceBlock) static dispatch_once_t onceToken; dispatch_once(&onceToken, onceBlock);//GCD - 一次性执行

#define ZSDISPATCH_MAIN_THREAD(mainQueueBlock) dispatch_async(dispatch_get_main_queue(), mainQueueBlock);//GCD - 在Main线程上运行

#define ZSDISPATCH_GLOBAL_QUEUE_DEFAULT(globalQueueBlock) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), globalQueueBlock);//GCD - 开启异步线程

//class转string

#define StringClass(Class) NSStringFromClass([Class class])

//防止空值赋值

#define NotNullStr(obj,nullObj) obj ? \

([obj isKindOfClass:[NSString class]] ? obj : \

([obj isKindOfClass:[NSNumber class]] ? [(NSNumber *)obj stringValue] : nullObj)) : \

nullObj

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,491评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,856评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,745评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,196评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,073评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,112评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,531评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,215评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,485评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,578评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,356评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,215评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,583评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,898评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,174评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,497评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,697评论 2 335

推荐阅读更多精彩内容

  • 来源于CocoaChina 在工作中, 很多小伙伴都会在PCH文件定义一些常用的宏,但是又怕写这些简单的宏浪费时间...
    iOS学末阅读 805评论 3 7
  • iOS开发过程中,使用的一些常用宏定义 字符串是否为空#define kStringIsEmpty(str) ([...
    goyohol阅读 5,334评论 30 85
  • 『导言』 iOS 开发常用宏总结的相关资料,需要的朋友可以参考下。文章中有不足之处请指正!谢谢! OC对象判断是否...
    随心吧阅读 839评论 0 16
  • 定义了一些常用的宏,写代码的时候用起来挺方便的,添加了pch文件,设置了相对路径;设置pch文件相对路径的方法:设...
    SnailLi阅读 1,644评论 0 1
  • #ifndef iOS_Constants_h #define iOS_Constants_h /* ******...
    莫离_焱阅读 269评论 0 1