常用全局宏定義

定義了一些常用的宏,寫代碼的時(shí)候用起來挺方便的,添加了pch文件,設(shè)置了相對路徑;
設(shè)置pch文件相對路徑的方法:
設(shè)置PCH的相對路徑
要想設(shè)置PCH的相對路徑,首先我們需要去查看絕對路徑。
相對路徑
點(diǎn)擊PCH文件,Xcode的右側(cè)會(huì)顯示PCH的屬性。這里我們可以獲取到PCH的絕對路徑。從工程的路徑開始,前面使用$(SRCROOT)代替,即為PCH的相對路徑。
設(shè)置相對路徑
在Xcode的target配置中,在Build Setting中找到Prefix Header,將修改后得到的相對路徑添加到其中,并將Precompile Prefix Header的值設(shè)置為YES。
運(yùn)行工程,PCH相對路徑設(shè)置成功。

// Created by 蝸牛 on 16/8/22.
// Copyright ? 2016年 *關(guān)于蝸牛:一枚九零后碼農(nóng) 蝸牛-----QQ:3197857495-----李富棚 個(gè)人微信:woniu1308822159 微信公眾號:woniuxueios 簡書:蝸牛學(xué)IOS 地址:http://www.lxweimin.com/users/a664a9fcb096/latest_articles 簡書專題:蝸牛學(xué)IOS 地址:http://www.lxweimin.com/collection/bfcf49bf5d27 蝸牛 */. All rights reserved.
//

ifndef MacroDefinition_h

define MacroDefinition_h

//************************ 獲取設(shè)備屏幕尺寸**********************************************

//寬度

define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width

//高度

define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

//大小

define SCREEN_SIZE [UIScreen mainScreen].bounds.size

//************************ 獲取設(shè)備屏幕尺寸**********************************************

//************************ 試圖的最大(小)X,Y 試圖 的 高度和寬度****************************
//試圖的最大(小)X,Y 試圖 的 高度和寬度

define GMXX(view) CGRectGetMaxX((view).frame)

define GMXY(view) CGRectGetMaxY((view).frame)

define GMIX(view) CGRectGetMinX((view).frame)

define GMIY(view) CGRectGetMinY((view).frame)

define GVH(view) CGRectGetHeight((view).frame)

define GVW(view) CGRectGetWidth((view).frame)

//************************ 試圖的最大(小)X,Y 試圖 的 高度和寬度****************************

//************************ 設(shè)備大小*****************************************************
//最大的屏幕長度

define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))

//最小屏幕長度

define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))

//iphone4/4s最大屏幕長度

define ISIPHONE4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)

//iphone5最大屏幕長度

define ISIPHONE5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)

//iphone6最大屏幕長度

define ISIPHONE6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)

//iphone6P最大屏幕長度

define ISIPHONE6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)

define ISIOS7_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.99)

define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)

pragma mark - ViewSize

define ScreenWidth (ISIPHONE6P? 414:(ISIPHONE6? 375:320))

define ScreenHeight (ISIPHONE6P? 736:(ISIPHONE6? 667:(ISIPHONE5? 568:480)))

define NavHeight 44

define StateHeight 20

//************************ 設(shè)備大小*****************************************************

//************************ 支持橫屏宏定義************************************************

//橫屏的寬度

define SCREEN_CROSS_WIDTH ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)]?[UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale:[UIScreen mainScreen].bounds.size.width)

//橫屏的高度

define SCREENH_CROSS_HEIGHT ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)]?[UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale:[UIScreen mainScreen].bounds.size.height)

//橫屏的大小

define SCREEN_CROSS_SIZE ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)]?CGSizeMake([UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale,[UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale):[UIScreen mainScreen].bounds.size)

//************************ 支持橫屏宏定義************************************************

//************************ 判斷當(dāng)前的設(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 5SE

define iPhone5SE [[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))

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

//************************ 判斷是真機(jī)還是模擬器********************************************

if TARGET_OS_IPHONE

//iPhone Device

endif

if TARGET_IPHONE_SIMULATOR

//iPhone Simulator

endif

//************************ 判斷是真機(jī)還是模擬器********************************************

//************************ 獲取通知中心**************************************************

define LFPNotificationCenter [NSNotificationCenter defaultCenter]

//************************ 獲取通知中心**************************************************

//************************ 設(shè)置顏色******************************************************

//隨機(jī)RGB顏色

define LFPRandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]

//設(shè)置RGB顏色

define RGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]

//設(shè)置RGBA顏色

define RGBAColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(r)/255.0 blue:(r)/255.0 alpha:a]

// rgb顏色轉(zhuǎn)換(16進(jìn)制->10進(jìn)制)

define RGB(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]

// clear背景顏色(清除背景色)

define ClearColor [UIColor clearColor]

//紅色背景色

define RED_Color [UIColor redColor]

//綠色背景色

define GREEN_Color [UIColor greenColor]

//黑色背景色

define BLACK_Color [UIColor blackColor]

//白色背景色

define WHITE_Color [UIColor whiteColor]

//灰色背景色

define GRAY_Color [UIColor grayColor]

//深灰色

define DARK_GRAY [UIColor darkGrayColor]

//淺灰色

define LIGHT_GRAY [UIColor lightGrayColor]

//青色

define CYAN_GRAY [UIColor cyanColor]

//黃色

define YELLOW_GRAY [UIColor yellowColor]

//品紅色

define MAGENTA_GRAY [UIColor magentaColor]

//橙色

define ORANGE_GRAY [UIColor orangeColor]

//紫色

define PURPLE_GRAY [UIColor purpleColor]

//布朗色

define BROWN_GRAY [UIColor brownColor]

//藍(lán)色

define BLUE_GRAY [UIColor blueColor]

//************************ 設(shè)置顏色******************************************************

//************************ NSUserDefaults 實(shí)例化 取值************************************

define USERDEFAULT [NSUserDefaults standardUserDefaults]

define USERDEFAULT_value(key) [[NSUserDefaults standardUserDefaults] valueForKey:key]

define USERDEFAULT_object(key) [[NSUserDefaults standardUserDefaults] objectForKey:key]

define USERDEFAULT_BOOL(key) [[NSUserDefaults standardUserDefaults] boolForKey:key]

define USERDEFAULT_integer(key) [[NSUserDefaults standardUserDefaults] integerForKey:key]

define USERDEFAULT_int(key) [[[NSUserDefaults standardUserDefaults] objectForKey:key] intValue]

//************************ NSUserDefaults 實(shí)例化 取值************************************

//************************ NSUserDefaults 實(shí)例化 存值************************************

//NSUserDefaults 實(shí)例化 存值
// object

define USERDEFAULT_SET_value(value,key) [[NSUserDefaults standardUserDefaults] setValue:value forKey:key];\

[[NSUserDefaults standardUserDefaults] synchronize]

define USERDEFAULT_SET_object(object,key) [[NSUserDefaults standardUserDefaults] setObject:object forKey:key];\

[[NSUserDefaults standardUserDefaults] synchronize]

// int

define USERDEFAULT_SET_int(int,key) NSString *uIntString=[NSString stringWithFormat:@"%d",int];\

[[NSUserDefaults standardUserDefaults] setObject:uIntString forKey:key];
[[NSUserDefaults standardUserDefaults] synchronize]

//float

define USERDEFAULT_SET_float(float,key) NSString *uFloatString=[NSString stringWithFormat:@"%f",float];\

[[NSUserDefaults standardUserDefaults] setObject:uFloatString forKey:key];
[[NSUserDefaults standardUserDefaults] synchronize]

define USERDEFAULT_SET_bool(bool,key) [[NSUserDefaults standardUserDefaults]setBool:bool forKey:key];\

[[NSUserDefaults standardUserDefaults] synchronize];

//************************ NSUserDefaults 實(shí)例化 存值************************************

//************************ 自定義高效率的 NSLog*******************************************

if DEBUG

define NSLog(FORMAT, ...) fprintf(stderr,"---[方法名:%s]\n---[行號:%d]\n---打印內(nèi)容:\n%s\n",FUNCTION, LINE,[[NSString stringWithFormat:FORMAT, ##VA_ARGS] UTF8String]);

else

define NSLog(FORMAT, ...) nil

endif

//************************ 自定義高效率的 NSLog*******************************************

/*
字體
*/

define Font(F) [UIFont systemFontOfSize:(F)]

/*
弱引用/強(qiáng)引用
*/
//弱引用

define WeakSelf(type) __weak typeof(type) weak##type = type;

//強(qiáng)引用

define StrongSelf(type) __strong typeof(type) type = weak##type;

//************************ 設(shè)置 view 圓角和邊框*******************************************
/*
設(shè)置 view 圓角和邊框
*/

define ViewBorderRadius(View, Radius, Width, Color,Bounds)\


[View.layer setCornerRadius:(Radius)];
[View.layer setMasksToBounds:(Bounds)];
[View.layer setBorderWidth:(Width)];
[View.layer setBorderColor:[Color CGColor]]

//************************ 設(shè)置 view 圓角和邊框*******************************************

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

define DegreesToRadian(x) (M_PI * (x) / 180.0)

define RadianToDegrees(radian) (radian*180.0)/(M_PI)

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

//************************ 獲取圖片資源*************************************************
//獲取圖片資源

define kGetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]

//************************ 獲取圖片資源*************************************************

//************************ 獲取當(dāng)前語言與地區(qū)********************************************
//獲取當(dāng)前語言與地區(qū)

define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

//************************ 獲取當(dāng)前語言與地區(qū)********************************************

//************************ GCD 的宏定義************************************************

//GCD - 一次性執(zhí)行

define kDISPATCH_ONCE_BLOCK(onceBlock) static dispatch_once_t onceToken; dispatch_once(&onceToken, onceBlock);

//GCD - 在Main線程上運(yùn)行

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);

//************************ GCD 的宏定義************************************************

pragma mark - localFont

/*font
Font18: 標(biāo)準(zhǔn)字36px18sp/18pt導(dǎo)航標(biāo)題、文章標(biāo)題、重要突出詞句
Font16: 標(biāo)準(zhǔn)字32px16sp/16pt用戶姓名、列表文章標(biāo)題、分類欄目、模塊名稱、按鈕文字等
Font14: 標(biāo)準(zhǔn)字28px14sp/14pt長段描述文字、非標(biāo)題文字、文章正文、提示性文字等
Font12: 標(biāo)準(zhǔn)字24px12sp/12pt次要描述文字、小副標(biāo)題、 次要提示、標(biāo)簽文字等
Font10: 標(biāo)準(zhǔn)字20px10sp/10pt標(biāo)簽欄名稱、次要長段描述或提示文字
*/

define Font(F) [UIFont systemFontOfSize:(F)]

define FontBold(F) [UIFont boldSystemFontOfSize:(F)]

define Font20 [UIFont fontWithName:@"Helvetica" size:20]

define Font20Bold [UIFont fontWithName:@"Helvetica-Bold" size:20]

define Font19 [UIFont fontWithName:@"Helvetica" size:19]

define Font19Bold [UIFont fontWithName:@"Helvetica-Bold" size:19]

define Font18 [UIFont fontWithName:@"Helvetica" size:18]

define Font18Bold [UIFont fontWithName:@"Helvetica-Bold" size:18]

define Font17 [UIFont fontWithName:@"Helvetica" size:17]

define Font17Bold [UIFont fontWithName:@"Helvetica-Bold" size:17]

define Font16 [UIFont fontWithName:@"Helvetica" size:16]

define Font16Bold [UIFont fontWithName:@"Helvetica-Bold" size:16]

define Font15 [UIFont fontWithName:@"Helvetica" size:15]

define Font15Bold [UIFont fontWithName:@"Helvetica-Bold" size:15]

define Font14 [UIFont fontWithName:@"Helvetica" size:14]

define Font14Bold [UIFont fontWithName:@"Helvetica-Bold" size:14]

define Font13 [UIFont fontWithName:@"Helvetica" size:13]

define Font13Bold [UIFont fontWithName:@"Helvetica-Bold" size:13]

define Font12 [UIFont fontWithName:@"Helvetica" size:12]

define Font12Bold [UIFont fontWithName:@"Helvetica-Bold" size:12]

define Font10 [UIFont fontWithName:@"Helvetica" size:10]

define Font10Bold [UIFont fontWithName:@"Helvetica-Bold" size:10]

define FontTitleNormal [UIFont fontWithName:@"Helvetica-Bold" size:15]

define FontPromptNormal [UIFont fontWithName:@"Helvetica" size:14]

endif /* MacroDefinition_h */

http://code.cocoachina.com/view/132637

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容