//
// PrefixHeader.pch
// JNdefine
//
// Created by Titan on 16/3/15.
// Copyright ? 2016年 pls. All rights reserved.
//
ifndef PrefixHeader_pch
define PrefixHeader_pch
//----------------------INSTALLATION 安裝方法----------------------------
//Added the prefix header file to PROJECT:
//1.Creat a new PCH files and named it with "PrefixHeader.pch"(default name or anything you want) .
//2.Click next and go to Build Settings search Prefix Header.
//3.Double click the blank address and put this address: $(SRCROOT)/$(PROJECT_NAME)/PrefixHeader.pch
//THEN YOU CAN USE THIS IN EVERY FILES IN THIS PROJECT. Good luck.
//如何安裝:
//1.創(chuàng)建新pch文件,默認(rèn)名字即可: "PrefixHeader.pch".
//2.點(diǎn)擊下一步再去Build Settings 搜索Prefix Header.
//3.找到Prefix Header并且雙擊,輸入$(SRCROOT)/$(PROJECT_NAME)/PrefixHeader.pch
//現(xiàn)在你可以在項(xiàng)目內(nèi)任何文件調(diào)用宏定義了,祝一切順利.
// Include any system framework and library headers here that should be included in all compilation units.
// You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.
//#endif /* PrefixHeader_pch */
//----------------------ABOUT SCREEN & SIZE 屏幕&尺寸 ----------------------------
/**
iPad Air {{0, 0}, {768, 1024}}
iphone4s {{0, 0}, {320, 480}} 960640
iphone5 5s {{0, 0}, {320, 568}} 1136640
iphone6 6s {{0, 0}, {375, 667}} 1334750
iphone6Plus 6sPlus {{0, 0}, {414, 736}} 19201080
Apple Watch 1.65inches(英寸) 320*640
*/
define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
define kTabBarH 49.0f
define kStatusBarH 20.0f
define kNavigationBarH 44.0f
define SCREEN_POINT (float)SCREEN_WIDTH/320.f
define SCREEN_H_POINT (float)SCREEN_HEIGHT/480.f
//判斷是否 Retina屏腺逛、設(shè)備是否iPhone 5、是否是iPad
define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
/** 判斷是否為iPhone */
define isiPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
/** 判斷是否是iPad */
define isiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
/** 判斷是否為iPod */
define isiPod ([[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"])
/** 設(shè)備是否為iPhone 4/4S 分辨率320x480至会,像素640x960栈源,@2x */
define iPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
/** 設(shè)備是否為iPhone 5C/5/5S 分辨率320x568团秽,像素640x1136易核,@2x */
define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
/** 設(shè)備是否為iPhone 6 分辨率375x667,像素750x1334米碰,@2x */
define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)
/** 設(shè)備是否為iPhone 6 Plus 分辨率414x736谷丸,像素1242x2208堡掏,@3x */
define iPhone6P ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)
//----------------------ABOUT SYSTYM & VERSION 系統(tǒng)與版本 ----------------------------
//Get the OS version. 判斷操作系統(tǒng)版本
define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
define CurrentSystemVersion ([[UIDevice currentDevice] systemVersion])
define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
//judge the simulator or hardware device 判斷是真機(jī)還是模擬器
if TARGET_OS_IPHONE
//iPhone Device
endif
if TARGET_IPHONE_SIMULATOR
//iPhone Simulator
endif
/** 獲取系統(tǒng)版本 */
define iOS_VERSION ([[[UIDevice currentDevice] systemVersion] floatValue])
define CurrentSystemVersion ([[UIDevice currentDevice] systemVersion])
/** 是否為iOS6 */
define iOS6 (([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0) ? YES : NO)
/** 是否為iOS7 */
define iOS7 (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) ? YES : NO)
/** 是否為iOS8 */
define iOS8 (([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) ? YES : NO)
/** 是否為iOS9 */
define iOS9 (([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0) ? YES : NO)
/** 獲取當(dāng)前語言 */
define kCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
//----------------------ABOUT PRINTING LOG 打印日志 ----------------------------
//Using dlog to print while in debug model. 調(diào)試狀態(tài)下打印日志
ifdef DEBUG
define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), PRETTY_FUNCTION, LINE, ##VA_ARGS);
else
define DLog(...)
endif
//Printing while in the debug model and pop an alert. 模式下打印日志,當(dāng)前行 并彈出一個(gè)警告
ifdef DEBUG
define ULog(fmt, ...) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", PRETTY_FUNCTION, LINE] message:[NSString stringWithFormat:fmt, ##VA_ARGS] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; }
else
define ULog(...)
endif
/** print 打印rect,size,point */
ifdef DEBUG
define kLogPoint(point) NSLog(@"%s = { x:%.4f, y:%.4f }", #point, point.x, point.y)
define kLogSize(size) NSLog(@"%s = { w:%.4f, h:%.4f }", #size, size.width, size.height)
define kLogRect(rect) NSLog(@"%s = { x:%.4f, y:%.4f, w:%.4f, h:%.4f }", #rect, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)
endif
//----------------------ABOUT COLOR 顏色相關(guān) ----------------------------
define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
// rgb顏色轉(zhuǎn)換(16進(jìn)制->10進(jìn)制)
define UIColorFromRGB(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]
//帶有RGBA的顏色設(shè)置
define COLOR(R, G, B, A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]
define kClearColor [UIColor clearColor]
define COLOR_BLUE_ UIColorFromRGB(0x41CEF2)
define COLOR_GRAY_ UIColorFromRGB(0xababab) //171
define COLOR_333 UIColorFromRGB(0x333333) //51
define COLOR_666 UIColorFromRGB(0x666666) //102
define COLOR_888 UIColorFromRGB(0x888888) //136
define COLOR_999 UIColorFromRGB(0x999999) //153
define COLOR_PLACEHOLD_ UIColorFromRGB(0xc5c5c5) //197
define COLOR_RED_ UIColorFromRGB(0xff5400) //紅色
define COLOR_GREEN_ UIColorFromRGB(0x31d8ab)//綠色
define COLOR_YELLOW_ UIColorFromRGB(0xffa200)//黃色
define COLOR_SEPARATE_LINE UIColorFromRGB(0xC8C8C8)//200
define COLOR_LIGHTGRAY COLOR(200, 200, 200, 0.4)//淡灰色
define MAX_WIDTH_10 (SCREEN_WIDTH-20)
define MAX_WIDTH_15 (SCREEN_WIDTH-30)
//----------------------ABOUT IMAGE 圖片 ----------------------------
//LOAD LOCAL IMAGE FILE 讀取本地圖片
define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]
//DEFINE IMAGE 定義UIImage對(duì)象// imgView.image = IMAGE(@"Default.png");
define IMAGE(A) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:A ofType:nil]]
//DEFINE IMAGE 定義UIImage對(duì)象
define ImageNamed(_pointer) [UIImage imageNamed:[UIUtil imageName:_pointer]]
//BETTER USER THE FIRST TWO WAY, IT PERFORM WELL. 優(yōu)先使用前兩種宏定義,性能高于后面.
//----------------------SOMETHING ELSE 其他 ----------------------------
define intToStr(S) [NSString stringWithFormat:@"%d",S]
//
//#define NotificationWarning(msg) [JDStatusBarNotification showWithStatus:msg dismissAfter:2.0 styleName:JDStatusBarStyleWarning]
//
//#define NotificationError(msg) [JDStatusBarNotification showWithStatus:msg dismissAfter:2.0 styleName:JDStatusBarStyleError]
//
//#define NotificationSuccess(msg) [JDStatusBarNotification showWithStatus:msg dismissAfter:2.0 styleName:JDStatusBarStyleSuccess]
/**
- the saving objects 存儲(chǔ)對(duì)象
- @param VALUE V
- @param KEY K
- @return
*/
define UserDefaultSetObjectForKey(VALUE,KEY) \
{
[[NSUserDefaults standardUserDefaults] setObject:VALUE forKey:KEY];
[[NSUserDefaults standardUserDefaults] synchronize];
}
/**
- get the saved objects 獲得存儲(chǔ)的對(duì)象
*/
define UserDefaultObjectForKey(KEY) [[NSUserDefaults standardUserDefaults] objectForKey:KEY]
/**
- delete objects 刪除對(duì)象
*/
define UserDefaultRemoveObjectForKey(KEY) \
{
[[NSUserDefaults standardUserDefaults] removeObjectForKey:KEY];
[[NSUserDefaults standardUserDefaults] synchronize];
}
define PLIST_TICKET_INFO_EDIT [NSHomeDirectory() stringByAppendingString:@"/Documents/data.plist"] //edit the plist
define TableViewCellDequeueInit(INDETIFIER) [tableView dequeueReusableCellWithIdentifier:(INDETIFIER)];
define TableViewCellDequeue(CELL,CELLCLASS,INDETIFIER) \
{
if (CELL == nil) {
CELL = [[CELLCLASS alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:INDETIFIER];
}
}
define KEYWINDOW [UIApplication sharedApplication].keyWindow
//Show Alert, brackets is the parameters. 宏定義一個(gè)彈窗方法,括號(hào)里面是方法的參數(shù)
define ShowAlert UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning." message:nil delegate:self cancelButtonTitle:@"cancel" otherButtonTitles: @"OK"];[alert show];
endif
//define an API 定義一個(gè)API
define APIURL @"http://www.google.com"
//login the API 登陸API
define APILogin [APIURL stringByAppendingString:@"Login"]
//GCD
define GCDWithGlobal(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
define GCDWithMain(block) dispatch_async(dispatch_get_main_queue(),block)
//NSUserDefaults 實(shí)例化
define USER_DEFAULT [NSUserDefaults standardUserDefaults]
//單例化 一個(gè)類
define SYNTHESIZE_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;
}
/** 快速查詢一段代碼的執(zhí)行時(shí)間 /
/* 用法
TICK
do your work here
TOCK
*/