屏幕尺寸
#define?kScreenWidth?[UIScreen mainScreen].bounds.size.width
#define?kScreenHeight?[UIScreen mainScreen].bounds.size.height
手機(jī)型號(hào)
#define kISiPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define kScreenMaxLength (MAX(kScreenWidth, kScreenHeight))
#define kScreenMinLength (MIN(kScreenWidth, kScreenHeight))
#define kISiPhone5 (kISiPhone && kScreenMaxLength == 568.0)
#definekISiPhone6 (kISiPhone && kScreenMaxLength == 667.0)
#definekISiPhone6P (kISiPhone && kScreenMaxLength == 736.0)
#definekISiPhoneX (kISiPhone && kScreenMaxLength == 812.0)
#definekISiPhoneXr (kISiPhone && kScreenMaxLength == 896.0)
#definekISiPhoneXX (kISiPhone && kScreenMaxLength > 811.0)
#defineIOS8 ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 8.0)系統(tǒng)版本
#defineIOS810 ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 10.0)
適配尺寸
//6為標(biāo)準(zhǔn)適配的,如果需要其他標(biāo)準(zhǔn)可以修改
#definekScale_W(w) ((kScreenWidth)/375) * (w)
#definekScale_H(h) (kScreenHeight/667) * (h)//狀態(tài)欄高度
#definekStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height//狀態(tài)欄高度
#defineStatusBarHeight (kISiPhoneX?44:20)//標(biāo)簽欄高度
#definekTabBarHeight (StatusBarHeight > 20 ? 83 : 49)//導(dǎo)航欄高度
#definekNavBarHeight (StatusBarHeight + 44)//安全區(qū)高度
#definekSafeAreaBottom (kISiPhoneX ? 34 : 0)
字體大小
#definekBoldFont(x) [UIFont boldSystemFontOfSize:x]
#definekFont(x) [UIFont systemFontOfSize:x]
顏色設(shè)置
//RGB格式
#definekRGB(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]//RGBA格式
#definekRGBA(r, g, b, a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
//隨機(jī)顏色
#definekRandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]
系統(tǒng)相關(guān)
//APP對(duì)象 (單例對(duì)象)
#definekApplication [UIApplication sharedApplication]//主窗口 (keyWindow)
#definekKeyWindow [UIApplication sharedApplication].keyWindow//NSUserDefaults實(shí)例化
#definekUserDefaults [NSUserDefaults standardUserDefaults]//通知中心 (單例對(duì)象)
#definekNotificationCenter [NSNotificationCenter defaultCenter]//發(fā)送通知
#defineKPostNotification(name,obj,info) [[NSNotificationCenter defaultCenter]postNotificationName:name object:obj userInfo:info]
//APP版本號(hào)
#definekVersion [[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleShortVersionString"]
//系統(tǒng)版本號(hào)
#definekSystemVersion [[UIDevice currentDevice] systemVersion]
?常用設(shè)置
//加載圖片
#definekGetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]
//弱引用#definekWeakSelf(type)? __weak typeof(type) weak##type = type
//強(qiáng)引用
#definekStrongSelf(type)? __strong typeof(type) type = weak##type
//安全調(diào)用Block
#definekSafeBlock(blockName,...) ({!blockName ? nil : blockName(__VA_ARGS__);})
//加載xib
#definekLoadNib(nibName) [UINib nibWithNibName:nibName bundle:[NSBundle mainBundle]]
//字符串拼接
#definekStringFormat(format,...) [NSString stringWithFormat:format,##__VA_ARGS__]
//屬性快速聲明(建議使用代碼塊)
#definekPropertyString(name) @property(nonatomic,copy)NSString *name
#definekPropertyStrong(type,name) @property(nonatomic,strong)type *name
#definekPropertyAssign(name) @property(nonatomic,assign)NSInteger name
日期時(shí)間
//獲得當(dāng)前的年份
#definekCurrentYear [[NSCalendar currentCalendar] component:NSCalendarUnitYear fromDate:[NSDate date]]
//獲得當(dāng)前的月份
#definekCurrentMonth [[NSCalendar currentCalendar] component:NSCalendarUnitMonth fromDate:[NSDate date]]
//獲得當(dāng)前的日期
#definekCurrentDay? [[NSCalendar currentCalendar] component:NSCalendarUnitDay fromDate:[NSDate date]]
//獲得當(dāng)前的小時(shí)
#definekCurrentHour [[NSCalendar currentCalendar] component:NSCalendarUnitHour fromDate:[NSDate date]]
//獲得當(dāng)前的分
#definekCurrentMin [[NSCalendar currentCalendar] component:NSCalendarUnitMinute fromDate:[NSDate date]]
//獲得當(dāng)前的秒
#definekCurrentSec [[NSCalendar currentCalendar] component:NSCalendarUnitSecond fromDate:[NSDate date]]
沙河路徑
//獲取沙盒 temp
#definekPathTemp NSTemporaryDirectory()
//獲取沙盒 Document
#definekPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
//獲取沙盒 Cache
#definekPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]
//Library/Caches 文件路徑
#definekFilePath ([[NSFileManager defaultManager] URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YESerror:nil])