99热99这里只有精品6国产,亚洲中文字幕在线天天更新,在线观看亚洲精品国产福利片 ,久久久久综合网

歡迎加入QQ討論群258996829
麥子學(xué)院 頭像
蘋果6袋
6
麥子學(xué)院

iOS學(xué)習(xí)之常用宏定義

發(fā)布時間:2017-02-13 12:56  回復(fù):0  查看:3475   最后回復(fù):2017-02-13 12:56  
在這里給大家分享一些 ios開發(fā)中常用的宏定義,喜歡的小伙伴可以直接在項目中使用。


目錄


1.獲取屏幕寬度與高度


2.獲取通知中心


3.設(shè)置隨機(jī)顏色


4.設(shè)置RGB顏色/設(shè)置RGBA顏色


5.自定義高效率的NSLog


6.弱引用/強(qiáng)引用


7.設(shè)置view圓角和邊框


8.由角度轉(zhuǎn)換弧度/由弧度轉(zhuǎn)換角度


9.獲取view的frame/圖片資源


10.獲取當(dāng)前語言


11.使用ARC和MRC


12.判斷當(dāng)前的iPhone設(shè)備/系統(tǒng)版本


13.沙盒目錄文件


14.GCD的宏定義


常用宏定義


1.獲取屏幕寬度與高度


#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
2.獲取通知中心


#define SHNotificationCenter [NSNotificationCenter defaultCenter]
3.設(shè)置隨機(jī)顏色


#define SHRandomColor [UIColor colorWithRed:arc4random_uniform(256) / 255.0 green:arc4random_uniform(256) / 255.0 blue:arc4random_uniform(256) / 255.0 alpha:1.0]
4.設(shè)置RGB顏色/設(shè)置RGBA顏色


#define SHRGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
#define SHRGBAColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:a]
5.自定義高效率的NSLog


#ifdef DEBUG
#define SHLog(...) NSLog(@"%s 第%d行 %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])
#else
#define SHLog(...)
#endif
6.弱引用/強(qiáng)引用


#define SHWeakSelf(type) __weak typeof(type) weak##type = type;
#define SHStrongSelf(type) __strong typeof(type) type = weak##type;
7.設(shè)置view圓角和邊框


#define SHViewBoarderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]
8.由角度轉(zhuǎn)換弧度/由弧度轉(zhuǎn)換角度


#define SHDegreesToRadian(x) (M_PI * (x) / 180.0)
#define SHRadianToDegrees(randian) (randian * 180.0) / (M_PI)
9.獲取view的frame/圖片資源


// 獲取view的frame
#define kGetViewWidth(view) view.frame.size.width
#define kGetViewHeight(view) view.frame.size.height
#define kGetViewX(view) view.frame.origin.x
#define kGetViewY(view) view.frame.origin.y
// 獲取圖片資源
#define kGetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]
10.獲取當(dāng)前語言


#define SHCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
11.使用ARC和MRC


#if __has_feature(objc_arc)
// ARC
#else
// MRC
#endif
12.判斷當(dāng)前的iPhone設(shè)備/系統(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 5/SE
#define iPhoneSE [[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))
13.沙盒目錄文件
// 獲取temp
#define kPathTemp NSTemporaryDirectory()
// 獲取沙盒 Document
#define kPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
// 獲取沙盒 Cache
#define kPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]
14.GCD的宏定義
// GCD - 一次性執(zhí)行
#define kDISPATCH_ONCE_BLOCK(onceBlock) static dispatch_once_t onceToken; dispatch_once(&onceToken, onceBlock);
// GCD - 在Main線程上運行
#define kDISPATCH_MAIN_THREAD(mainQueueBlock) dispatch_async(dispatch_get_main_queue(), mainQueueBlock);
// GCD - 開啟異步線程
#define kDISPATCH_GLOBAL_QUEUE_DEFAULT(globalQueueBlock) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), globalQueueBlocl);


來源:簡書
您還未登錄,請先登錄

熱門帖子

最新帖子

?