都是項目中常用的船响,16進(jìn)制色值轉(zhuǎn)換,默認(rèn)字體設(shè)置字號大小躲履,判斷主線程见间,獲取當(dāng)前Version,Build工猜,沙盒路徑米诉,緩存路徑,屏幕物理寬篷帅、高史侣,基于iPhone5尺寸的縮放值,當(dāng)前手機版本魏身,weakself等等惊橱。
- 2015.04.27 更新
新增比較當(dāng)前系統(tǒng)版本號與輸入值(NSString)
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
需要的就直接拷走好啦。
/*--------------------------------開發(fā)中常用到的宏定義-----------------------------------*/
// 顏色的轉(zhuǎn)換
#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]
#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]
//16進(jìn)制色值
#define HexRGB(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]
#define HexRGBAlpha(rgbValue, a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:(a)]
//設(shè)置系統(tǒng)默認(rèn)字體的字號
#define FONT(x) [UIFont systemFontOfSize:x]
// 判斷是否在主線程
#define DONT_BLOCK_UI() \\
NSAssert(![NSThread isMainThread], @"Don't block the UI thread please!")
#define BLOCK_UI() \\
NSAssert([NSThread isMainThread], @"You aren't running in the UI thread!")
//導(dǎo)航條高度
#define CUSTOM_NAV_HEIGHT 44
//當(dāng)前build號
#define Current_Build [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
#define Current_Version [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
//常用系統(tǒng)庫
#define USER_DEFAULT [NSUserDefaults standardUserDefaults]
#define NOTIFICATION_CENTER [NSNotificationCenter defaultCenter]
//沙盒存儲路徑
#define HomeDirectory [NSHomeDirectory() stringByAppendingString:@"/Documents/"]
//緩存路徑
#define APP_CACHES_PATH [NSSearchPathForDirectoriesInDomains (NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]
//屏幕物理寬箭昵、高
#define APP_SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define APP_SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
//與iPhone5比較的尺寸縮放值
#define kScaleFrom_iPhone5_Desgin(_X_) (_X_ * (APP_SCREEN_WIDTH/320))
//手機版本
#define Current_device_vesion [[[UIDevice currentDevice] systemVersion] floatValue]
//按屏幕尺寸確定手機
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
//比較當(dāng)前系統(tǒng)版本號與輸入值(NSString)
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
//weakself 用與防止循環(huán)引用
#define WS(weakSelf) __weak __typeof(&*self)weakSelf = self;
以后遇到新的好用的宏定義也會添加到這里税朴,謝謝您的閱讀。