----------------獲取設(shè)備信息------------------
#define kNavigationBar_HEIGHT 44 //導(dǎo)航條高度
#define kStatusBar_HEIGHT 20 //狀態(tài)欄高度
#define kScreen_Width ([UIScreen mainScreen].bounds.size.width) //屏幕寬度
#define kScreen_Height ([UIScreen mainScreen].bounds.size.height)//屏幕高度
//判斷是否 是Retina屏
#define kIsRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
#define kIsPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) //是否是 iPad
//iphone4
#define kIS_IPHONE_4 ([[UIScreen mainScreen] bounds].size.height == 480.0f)
//iphone5,5C,5S
#define kIS_IPHONE_5 ([[UIScreen mainScreen] bounds].size.height == 568.0f)
//iphone 6,6S
#define kIS_IPHONE_6 ([[UIScreen mainScreen] bounds].size.height == 667.0f)
//iphone 6 puls ,6s puls
#define kIS_IPHONE_6_PULS ([[UIScreen mainScreen] bounds].size.height == 736.0f)
//IPad Retina
#define IS_IPAD_RETINA ([[UIScreen mainScreen] bounds].size.height == 1024.0f)
//IPad pro
#define IS_IPAD_PRO ([[UIScreen mainScreen] bounds].size.height == 1366.0f)
//IPad 2, Air, Air2
#define IS_IPAD_AIR ([[UIScreen mainScreen] bounds].size.height == 1024.0f)
----------------獲取系統(tǒng)信息------------------
//系統(tǒng)版本-float
#define kIOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
//系統(tǒng)版本-string
#define kCurrentSystemVersion ([[UIDevice currentDevice] systemVersion])
//系統(tǒng)語(yǔ)言
#define kCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
------------------IOS 版本-------------------
#define kIOS5_OR_LATER ( [[[UIDevice currentDevice] systemVersion] compare:@"5.0"] != NSOrderedAscending )
#define kIOS6_OR_LATER ( [[[UIDevice currentDevice] systemVersion] compare:@"6.0"] != NSOrderedAscending )
#define kIOS7_OR_LATER ( [[[UIDevice currentDevice] systemVersion] compare:@"7.0"] != NSOrderedAscending )
#define kIOS8_OR_LATER ( [[[UIDevice currentDevice] systemVersion] compare:@"8.0"] != NSOrderedAscending )
#define kIOS9_OR_LATER ( [[[UIDevice currentDevice] systemVersion] compare:@"9.0"] != NSOrderedAscending )
-----------------字體大小---------------------
#define kFont_10 [UIFont systemFontOfSize:10]
#define kFont_11 [UIFont systemFontOfSize:11]
#define kFont_12 [UIFont systemFontOfSize:12]
#define kFont_13 [UIFont systemFontOfSize:13]
#define kFont_14 [UIFont systemFontOfSize:14]
#define kFont_15 [UIFont systemFontOfSize:15]
#define kFont_16 [UIFont systemFontOfSize:16]
#define kFont_17 [UIFont systemFontOfSize:17]
#define kFont_18 [UIFont systemFontOfSize:18]
//自定義字體大小
#define kFont(X) [UIFont systemFontOfSize:X]
-----------------RGB 轉(zhuǎn)換---------------------
#define kRGBColor(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]
#define kRGBAColor(r,g,b,a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]
-----------------判斷是否為空---------------------
#define kNotNilAndNull(_ref) (((_ref) != nil) && (![(_ref) isEqual:[NSNull null]]))
#define kIsNilOrNull(_ref) (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]]))
---------------------圖片資源獲取---------------------
#define kImgFromBundle(file,ext ) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]
#define kImgNamed(file) [UIImage imageNamed:file]
---------------------沙盒---------------------
//沙盒存儲(chǔ)路徑
#define kHomeDirectory [NSHomeDirectory() stringByAppendingString:@"/Documents/"]
//緩存路徑
#define kApp_Caches_Path [NSSearchPathForDirectoriesInDomains (NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]
---------------------單例化一個(gè)類(lèi)---------------
#define kSYNTHESIZE_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; \
}
pch 簡(jiǎn)介
pch 文件是一個(gè)標(biāo)準(zhǔn)的預(yù)編譯頭文件 (Pre-Compiled Header),在 Xcode6 之前的版本中,系統(tǒng)模板會(huì)在 Supporting Files 文件夾自動(dòng)創(chuàng)建琢融。但在 Xcode6 之后的版本中取消了這一文件举反,如果我們需要使用 pch 文件凳忙,則需要手動(dòng)創(chuàng)建埃疫。 方法如下.
在 xcode 中添加 pch 全局引用文件的方法:
1.新建一個(gè) pch 文件 xxxxx.pch;
2.在TARGETS下的Building Settings -> Prefix Header -> $(SRCROOT)/xxxxx.pch
注: $(SRCROOT)/xxxxx.pch 此處不是絕對(duì),跟 pch 文件存放路徑有關(guān)
補(bǔ)充:
1.將 Precompile Prefix Header 為 YES帚湘,預(yù)編譯后的 pch 文件會(huì)被緩存起來(lái)哮针,可以提高編譯速度锤窑。
2.在 pch 文件中不要進(jìn)行頭文件引入璧针,雖然這樣很省事,但是犧牲的是編譯速度渊啰。引入頭文件可以專門(mén)建一個(gè). h 文件進(jìn)行引頭探橱。