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