宏定義

//單例
#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)

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容