常用的宏(可直接拿來用)


//----------------------圖片相關(guān)----------------------------

//讀取本地圖片

#define LoadImage(file,type) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:type]]

#define LoadPNGImage(file) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:@"png"]]

//定義UIImage對(duì)象

#define ImageNamed(name) [UIImage imageNamed:name]

//可拉伸的圖片

#define ResizableImage(name,top,left,bottom,right) [[UIImage imageNamed:name] resizableImageWithCapInsets:UIEdgeInsetsMake(top,left,bottom,right)]

#define ResizableImageWithMode(name,top,left,bottom,right,mode) [[UIImage imageNamed:name] resizableImageWithCapInsets:UIEdgeInsetsMake(top,left,bottom,right) resizingMode:mode]

//圖片尺寸

#define CustomSizeImage(url,width,height) [NSString stringWithFormat:@"%@?imageView2/1/w/%d/h/%d",url,width,height]

//----------------------顏色相關(guān)---------------------------

// 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]

// 獲取RGB顏色

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

#define RGB(r,g,b) RGBA(r,g,b,1.0f)

//字體定義

#define FONT(F) [UIFont systemFontOfSize:F]

//[UIFont fontWithName:@"Source Han Sans CN" size:F]

#define FONTSYSTEMBOLD(F) [UIFont boldSystemFontOfSize:F]

//----------------------系統(tǒng)設(shè)備相關(guān)----------------------------

//獲取Window

#define WINDOW [UIApplication sharedApplication].keyWindow

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

#define ScreenWidth ([UIScreen mainScreen].bounds.size.width)

#define ScreenHeight ([UIScreen mainScreen].bounds.size.height)

#define APP_WIDTH [[UIScreen mainScreen]applicationFrame].size.width

#define APP_HEIGHT [[UIScreen mainScreen]applicationFrame].size.height

//獲取系統(tǒng)版本

#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]

#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]

#define isIOS4 ([[[UIDevice currentDevice] systemVersion] intValue]==4)

#define isIOS5 ([[[UIDevice currentDevice] systemVersion] intValue]==5)

#define isIOS6 ([[[UIDevice currentDevice] systemVersion] intValue]==6)

#define isIOS7 ([[[UIDevice currentDevice] systemVersion] intValue]==7)

#define isIOS8 ([[[UIDevice currentDevice] systemVersion] intValue]==8)

#define isIOS9 ([[[UIDevice currentDevice] systemVersion] intValue]==9)

#define isAfterIOS4 ([[[UIDevice currentDevice] systemVersion] intValue]>4)

#define isAfterIOS5 ([[[UIDevice currentDevice] systemVersion] intValue]>5)

#define isAfterIOS6 ([[[UIDevice currentDevice] systemVersion] intValue]>6)

#define isAfterIOS7 ([[[UIDevice currentDevice] systemVersion] intValue]>7)

#define isAfterIOS8 ([[[UIDevice currentDevice] systemVersion] intValue]>8)

#define isIOS4OrAfter ([[[UIDevice currentDevice] systemVersion] intValue]>=4)

#define isIOS5OrAfter ([[[UIDevice currentDevice] systemVersion] intValue]>=5)

#define isIOS6OrAfter ([[[UIDevice currentDevice] systemVersion] intValue]>=6)

#define isIOS7OrAfter ([[[UIDevice currentDevice] systemVersion] intValue]>=7)

#define isIOS8OrAfter ([[[UIDevice currentDevice] systemVersion] intValue]>=8)

//獲取當(dāng)前語言

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

//判斷是否 Retina屏、設(shè)備是否iphone 5毙玻、是否是iPad

#define isIphone6OrAfter [[UIScreen mainScreen] bounds].size.width > 320.0f

#define iPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)

#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)

#define iPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)

#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

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

#if TARGET_OS_IPHONE

//iPhone Device

#endif

#if TARGET_IPHONE_SIMULATOR

//iPhone Simulator

#endif

//----------------------視圖相關(guān)----------------------------

//得到視圖的left top的X,Y坐標(biāo)點(diǎn)

#define VIEW_TX(view) (view.frame.origin.x)

#define VIEW_TY(view) (view.frame.origin.y)

//得到視圖的right bottom的X,Y坐標(biāo)點(diǎn)

#define VIEW_BX(view) (view.frame.origin.x + view.frame.size.width)

#define VIEW_BY(view) (view.frame.origin.y + view.frame.size.height)

//得到視圖的尺寸:寬度豌蟋、高度

#define VIEW_W(view)? (view.frame.size.width)

#define VIEW_H(view)? (view.frame.size.height)

//得到frame的X,Y坐標(biāo)點(diǎn)

#define FRAME_X(frame)? (frame.origin.x)

#define FRAME_Y(frame)? (frame.origin.y)

//得到frame的寬度、高度

#define FRAME_W(frame)? (frame.size.width)

#define FRAME_H(frame)? (frame.size.height)

//---------------------打印日志--------------------------

//打印Frame

#define LogFrame(frame) NSLog(@"Frame[X=%.1f,Y=%.1f,W=%.1f,H=%.1f",frame.origin.x,frame.origin.y,frame.size.width,frame.size.height)

//打印Size

#define LogSize(size) NSLog(@"Size[W=%.1f,H=%.1f",size.width,size.height)

//打印Point

#define LogPoint(point) NSLog(@"Point[X=%.1f,Y=%.1f]",point.x,point.y)

//打印Log

#define Log(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

//file

//讀取文件的文本內(nèi)容,默認(rèn)編碼為UTF-8

#define FileString(name,ext)? ? ? ? ? ? [[NSString alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(name) ofType:(ext)] encoding:NSUTF8StringEncoding error:nil]

#define FileDictionary(name,ext)? ? ? ? [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(name) ofType:(ext)]]

#define FileArray(name,ext)? ? ? ? ? ? [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(name) ofType:(ext)]]

//G-C-D

#define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)

#define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)

//Alert

#define ALERT(msg) [[[UIAlertView alloc] initWithTitle:nil message:msg delegate:nil cancelButtonTitle:@"確定" otherButtonTitles:nil] show]

//----------------------程序相關(guān)----------------------------

// 應(yīng)用程序托管

#define AppDelegateInstance ((AppDelegate*)([UIApplication sharedApplication].delegate))

// 本地存儲(chǔ)

#define UserDefaults [NSUserDefaults standardUserDefaults]

// 通知中心

#define NotificationCenter [NSNotificationCenter defaultCenter]

//由角度獲取弧度 有弧度獲取角度

#define degreesToRadian(x) (M_PI * (x) / 180.0)

#define radianToDegrees(radian) (radian*180.0)/(M_PI)

//字符串

#define AppendString(string,addstring) [string stringByAppendingString:addstring]

//----------------------內(nèi)存相關(guān)----------------------------

#ifndef weakify

#if DEBUG

#if __has_feature(objc_arc)

#define weakify(object) autoreleasepool{} __weak __typeof__(object) weak##_##object = object;

#else

#define weakify(object) autoreleasepool{} __block __typeof__(object) block##_##object = object;

#endif

#else

#if __has_feature(objc_arc)

#define weakify(object) try{} @finally{} {} __weak __typeof__(object) weak##_##object = object;

#else

#define weakify(object) try{} @finally{} {} __block __typeof__(object) block##_##object = object;

#endif

#endif

#endif

#ifndef strongify

#if DEBUG

#if __has_feature(objc_arc)

#define strongify(object) autoreleasepool{} __typeof__(object) object = weak##_##object;

#else

#define strongify(object) autoreleasepool{} __typeof__(object) object = block##_##object;

#endif

#else

#if __has_feature(objc_arc)

#define strongify(object) try{} @finally{} __typeof__(object) object = weak##_##object;

#else

#define strongify(object) try{} @finally{} __typeof__(object) object = block##_##object;

#endif

#endif

#endif

// block self

#define WEAKSELF typeof(self) __weak weakSelf = self;

#define STRONGSELF typeof(weakSelf) __strong strongSelf = weakSelf;

//釋放一個(gè)對(duì)象

#define SAFE_DELETE(P) if(P) { [P release], P = nil; }

#define SAFE_RELEASE(x) [x release];x=nil

#define SuppressPerformSelectorLeakWarning(Stuff) \

do { \

_Pragma("clang diagnostic push") \

_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \

Stuff; \

_Pragma("clang diagnostic pop") \

} while (0)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末桑滩,一起剝皮案震驚了整個(gè)濱河市梧疲,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌运准,老刑警劉巖幌氮,帶你破解...
    沈念sama閱讀 206,214評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異胁澳,居然都是意外死亡该互,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,307評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門韭畸,熙熙樓的掌柜王于貴愁眉苦臉地迎上來宇智,“玉大人蔓搞,你說我怎么就攤上這事∷骈伲” “怎么了喂分?”我有些...
    開封第一講書人閱讀 152,543評(píng)論 0 341
  • 文/不壞的土叔 我叫張陵,是天一觀的道長太防。 經(jīng)常有香客問我妻顶,道長,這世上最難降的妖魔是什么蜒车? 我笑而不...
    開封第一講書人閱讀 55,221評(píng)論 1 279
  • 正文 為了忘掉前任讳嘱,我火速辦了婚禮,結(jié)果婚禮上酿愧,老公的妹妹穿的比我還像新娘沥潭。我一直安慰自己,他們只是感情好嬉挡,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,224評(píng)論 5 371
  • 文/花漫 我一把揭開白布钝鸽。 她就那樣靜靜地躺著,像睡著了一般庞钢。 火紅的嫁衣襯著肌膚如雪拔恰。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,007評(píng)論 1 284
  • 那天基括,我揣著相機(jī)與錄音颜懊,去河邊找鬼。 笑死风皿,一個(gè)胖子當(dāng)著我的面吹牛河爹,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播桐款,決...
    沈念sama閱讀 38,313評(píng)論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼咸这,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了魔眨?” 一聲冷哼從身側(cè)響起媳维,我...
    開封第一講書人閱讀 36,956評(píng)論 0 259
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎冰沙,沒想到半個(gè)月后侨艾,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,441評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡拓挥,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,925評(píng)論 2 323
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了袋励。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片侥啤。...
    茶點(diǎn)故事閱讀 38,018評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡当叭,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出盖灸,到底是詐尸還是另有隱情蚁鳖,我是刑警寧澤,帶...
    沈念sama閱讀 33,685評(píng)論 4 322
  • 正文 年R本政府宣布赁炎,位于F島的核電站醉箕,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏徙垫。R本人自食惡果不足惜讥裤,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,234評(píng)論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望姻报。 院中可真熱鬧己英,春花似錦、人聲如沸吴旋。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,240評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽荣瑟。三九已至治拿,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間笆焰,已是汗流浹背劫谅。 一陣腳步聲響...
    開封第一講書人閱讀 31,464評(píng)論 1 261
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留仙辟,地道東北人同波。 一個(gè)月前我還...
    沈念sama閱讀 45,467評(píng)論 2 352
  • 正文 我出身青樓,卻偏偏與公主長得像叠国,于是被迫代替她去往敵國和親未檩。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,762評(píng)論 2 345

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