1 weakself和strongself
#ifndef weakify
#if DEBUG
#ifhas_feature(objc_arc)
#define weakify(object) autoreleasepool{} __weak __typeof(object) weak####object = object;
#else
#define weakify(object) autoreleasepool{} __block __typeof_(object) block####object = object;
#endif
#else
#if __has_feature(objc_arc)
#define weakify(object) try{}@finally{} {} __weak __typeof_(object) weak####object = object;
#else
#define weakify(object) try{}@finally{} {} __block __typeof_(object) block##_##object = object;
#endif
#endif
#endif
#ifndef strongify
#if DEBUG
#ifhas_feature(objc_arc)
#define strongify(object) autoreleasepool{} __typeof(object) object = weak####object;
#else
#define strongify(object) autoreleasepool{} __typeof_(object) object = block####object;
#endif
#else
#if __has_feature(objc_arc)
#define strongify(object) try{}@finally{} __typeof_(object) object = weak####object;
#else
#define strongify(object) try{}@finally{} __typeof_(object) object = block##_##object;
#endif
#endif
#endif
2 獲取設備大小
#define NavigationBar_HEIGHT 44
3 獲取屏幕 寬度伙狐、高度
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
4 打印日志
#ifdef DEBUG
define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt),PRETTY_FUNCTION,LINE, ##VA_ARGS);
#else
define DLog(...)
#endif
5 重寫NSLog,Debug模式下打印日志和當前行數(shù)
#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
6 是否是ipad
#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
7 獲取系統(tǒng)版本
#define IOS_VERSION [[UIDevice currentDevice] systemVersion] floatValue]
#define CurrentSystemVersion [UIDevice currentDevice] systemVersion]
8 獲取當前系統(tǒng)的語言
#define CurrentLanguage ([NSLocale preferredLanguages] objectAtIndex:0])
9 判斷設備的操做系統(tǒng)是不是ios7
#define IOS7 ([[UIDevice currentDevice].systemVersion doubleValue] >= 7.0]
10 判斷是真機還是模擬器
#if TARGET_OS_IPHONE
//iPhone Device
#endif
#if TARGET_IPHONE_SIMULATOR
//iPhone Simulator
#endif
11 顏色值轉換
// 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]
12 由角度獲取弧度 有弧度獲取角度
#define degreesToRadian(x) (M_PI * (x) / 180.0)
#define radianToDegrees(radian) (radian*180.0)/(M_PI)
13 單例
//單例化一個類
#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; \ } 14 沙盒目錄文件 //獲取temp #define kPathTemp NSTemporaryDirectory() //獲取沙盒 Document #define kPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] //獲取沙盒 Cache #define kPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject] 15 設置 view 圓角和邊框 #define LRViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]
16 .判斷當前的iPhone設備/系統(tǒng)版本
//判斷是否為iPhone
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
//判斷是否為iPad
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
//判斷是否為ipod
#define IS_IPOD ([[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"])
// 判斷是否為 iPhone 5SE
#define iPhone5SE [[UIScreen mainScreen] bounds].size.width == 320.0f && [[UIScreen mainScreen] bounds].size.height == 568.0f
// 判斷是否為iPhone 6/6s
#define iPhone6_6s [[UIScreen mainScreen] bounds].size.width == 375.0f && [[UIScreen mainScreen] bounds].size.height == 667.0f
// 判斷是否為iPhone 6Plus/6sPlus
#define iPhone6Plus_6sPlus [[UIScreen mainScreen] bounds].size.width == 414.0f && [[UIScreen mainScreen] bounds].size.height == 736.0f
//獲取系統(tǒng)版本
#define IOS_SYSTEM_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
//判斷 iOS 8 或更高的系統(tǒng)版本
#define IOS_VERSION_8_OR_LATER (([[[UIDevice currentDevice] systemVersion] floatValue] >=8.0)? (YES):(NO))
#ifdef ITTDEBUG
#define ITTDPRINT(xx, ...)? NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#define ITTDPRINT(xx, ...)? ((void)0)
#endif