- 最近忙著寫項(xiàng)目,就整理了一下 項(xiàng)目中經(jīng)常用到的宏
- 字體根據(jù)機(jī)型自適應(yīng).檢查系統(tǒng)版本
- 機(jī)型適配,比例,強(qiáng)弱引用,日志,圖片等
- 如果你還有一些好用的宏,可以互相交流一下
/*
*調(diào)試日志開關(guān)
*/
#define __APPSTORE___ 0
#if __APPSTORE___
#define NSLog(format, ...)
#else
#define NSLog(format, ...) NSLog(format, ## __VA_ARGS__)
#endif
/**
* 導(dǎo)航控制器高度
*/
#define NavcHeight 64.0
/**
* tarbar的高度
*/
#define TarBarHeight 49.0
/**
* 字體適配宏
*/
//不同屏幕尺寸字體適配
#define CHINESE_FONT_NAME @"Heiti SC"
#define CHINESE_SYSTEM(x) [UIFont fontWithName:CHINESE_FONT_NAME size:x]
#define kScreenWidthRatio (iphoneWidth / 414.0)
#define kScreenHeightRatio (iphoneHeigh / 736.0)
#define AdaptedWidth(x) ceilf((x) * kScreenWidthRatio)
#define AdaptedHeight(x) ceilf((x) * kScreenHeightRatio)
#define AdaptedFontSize(R) CHINESE_SYSTEM(AdaptedWidth(R))
/**
* 弱引用
*/
#define _WeakSelf __weak typeof(self) weakSelf = self
#define WeakObj(o) autoreleasepool{} __weak typeof(o) o##Weak = o;
//NSUserDefaults 實(shí)例化
#define USER_DEFAULT [NSUserDefaults standardUserDefaults]
//G-C-D
#define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)
//獲取圖片資源
#define GetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]
#define GetUlr(url) [NSURL URLWithString:url]
#define SetImaged(url) sd_setImageWithURL:GetUlr(url)
//讀取本地圖片 性能比[UIImage imageNamed: 性能強(qiáng)很多]
//例如 imageView.image = LOADIMAGE(@"文件名",@"png");
#define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]
//定義UIImage對(duì)象
#define IMAGE(A) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:A ofType:nil]]
//由角度獲取弧度 有弧度獲取角度
#define degreesToRadian(x) (M_PI * (x) / 180.0)
#define radianToDegrees(radian) (radian*180.0)/(M_PI)
//設(shè)置手機(jī)屏幕,判斷機(jī)型
#define iphoneWidth [UIScreen mainScreen].bounds.size.width
#define iphoneHeigh [UIScreen mainScreen].bounds.size.height
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
#define SCREEN_MAX_LENGTH (MAX(iphoneWidth, iphoneHeigh))
#define SCREEN_MIN_LENGTH (MIN(iphoneWidth, iphoneHeigh))
#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
#define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)
// 檢查系統(tǒng)版本
#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)
// 縮放比
#define kScale iphoneWidth / 375
#define hScale iphoneHeigh / 667
//使用ARC和不使用ARC
#if __has_feature(objc_arc)
//compiling with ARC
#else
// compiling without ARC
#endif
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者