宏定义

作者: MindTheGap | 来源:发表于2015-07-23 11:31 被阅读94次

//单例
#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; \
}

//根据比例按宽度计算高度
#define getHeightByRate(oriWidth,oriHeight,newWidth) newWidth*oriHeight/oriWidth

//根据比例按高度计算宽度
#define getWidthByRate(oriWidth,oriHeight,newHeight) newHeight*oriWidth/oriHeight

//根据宽度计算在屏幕水平居中的X坐标开始位置
#define getCenterXByWith(oriWidth) (SCREEN_BOUNDS.size.width-oriWidth)/2

//判断字符串是否为空
#define NSStringIsNullOrEmpty(string) ({NSString *str=(string);(str==nil || [str isEqual:[NSNull null]] ||  str.length == 0 || [str isKindOfClass:[NSNull class]] || [[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] isEqualToString:@""])?YES:NO;})

//系统类型
#define isbeforeIOS7 ([[[UIDevice currentDevice]systemVersion]floatValue] < 7.0?YES:NO)

#define isIOS7AndLater ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0?YES:NO)

//ios系统版本
#define ios8 [[[UIDevice currentDevice] systemVersion] floatValue] >=8.0f
#define ios7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f) && ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0f)
#define ios6 [[[UIDevice currentDevice] systemVersion] floatValue] < 7.0f
#define ios7AndLater [[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f

//方正黑体简体字体定义
#define FONT(F) [UIFont fontWithName:@"FZHTJW--GB1-0" size:F]

//G-C-D
#define GCD_BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define GCD_MAIN(block) dispatch_async(dispatch_get_main_queue(),block)

相关文章

  • C语言 预处理指令

    一 .宏定义 #define 宏定义宏定义会在预处理的时候,用宏定义的值来替换宏的名称 定义格式 "#define...

  • swift&&OC

    宏定义 OC中的宏定义 swift中的宏定义 OC中宏定义的方式,在swift中是不可用的,在swift中,宏定义...

  • [iOS功能]- 宏定义

    单行宏定义 多行宏定义

  • 准备:回顾c

    宏定义 关键字 define 定义一个常量的方法(即宏定义) 带参数的宏定义 宏函数的定义 使用宏函数的好处是,不...

  • c高级自我学习(1)

    1 编译预处理和宏定 #undef指令删除前面定义的宏定义。 无参宏定义:宏名中没有参数。 1,宏定义中宏名用来表...

  • 5月31

    今天学习了宏定义 宏定义分为:不带参数的宏定义和带参数的宏定义,不占用任何内存空间,宏定义时不加分号。 #defi...

  • 总结

    宏定义:宏定义的分为无参宏定义与有参宏定义。无参宏定义的一般形式为:#define 标识符 字符串。‘#’表示...

  • 10/19

    今天老师讲了预处理命令,宏定义分为无参宏定义,带参宏定义和条件编译。宏定义包括宏名和宏展开,和函数相比预处理有很多...

  • C语言预处理指令

    预处理指令 宏定义 宏定义会在预处理的时候, 用宏定义的值来替换宏的名称 格式: #define 宏名称 宏值 应...

  • C语言学习:C语言宏定义

    学C语言很久了,但还是不敢用宏定义,大神喜欢用宏定义。关于宏定义你又了解多少了,下面我们说一下宏定义。 宏定义的概...

网友评论

      本文标题:宏定义

      本文链接:https://www.haomeiwen.com/subject/qeapqttx.html