ios開發常用的巨集
轉載自 http://www.cocoachina.com/bbs/read.php?tid=137317&page=1
//use stringmake for NSString
#define StringMake(fmt, ...) [NSString stringWithFormat:(@"%s [Line %d] " fmt),__PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__]
#define NavigationBar_HEIGHT 44 #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width) #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height) #define SAFE_RELEASE(x) [x release];x=nil #define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue] #define CurrentSystemVersion ([[UIDevice currentDevice] systemVersion]) #define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0]) #define BACKGROUND_COLOR [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0] //use dlog to print while in debug model #ifdef DEBUG # define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); #else # define DLog(...) #endif #define isRetina ([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 isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) #if TARGET_OS_IPHONE //iPhone Device #endif #if TARGET_IPHONE_SIMULATOR //iPhone Simulator #endif //ARC #if __has_feature(objc_arc) //compiling with ARC #else // compiling without ARC #endif //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) #define USER_DEFAULT [NSUserDefaults standardUserDefaults] #define ImageNamed(_pointer) [UIImage imageNamed:[UIUtil imageName:_pointer]] #pragma mark - common functions #define RELEASE_SAFELY(__POINTER) { [__POINTER release]; __POINTER = nil; } #pragma mark - degrees/radian functions #define degreesToRadian(x) (M_PI * (x) / 180.0) #define radianToDegrees(radian) (radian*180.0)/(M_PI) #pragma mark - color functions #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)] #define ITTDEBUG #define ITTLOGLEVEL_INFO 10 #define ITTLOGLEVEL_WARNING 3 #define ITTLOGLEVEL_ERROR 1 #ifndef ITTMAXLOGLEVEL #ifdef DEBUG #define ITTMAXLOGLEVEL ITTLOGLEVEL_INFO #else #define ITTMAXLOGLEVEL ITTLOGLEVEL_ERROR #endif #endif // The general purpose logger. This ignores logging levels. #ifdef ITTDEBUG #define ITTDPRINT(xx, ...) NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__) #else #define ITTDPRINT(xx, ...) ((void)0) #endif // Prints the current method's name. #define ITTDPRINTMETHODNAME() ITTDPRINT(@"%s", __PRETTY_FUNCTION__) // Log-level based logging macros. #if ITTLOGLEVEL_ERROR <= ITTMAXLOGLEVEL #define ITTDERROR(xx, ...) ITTDPRINT(xx, ##__VA_ARGS__) #else #define ITTDERROR(xx, ...) ((void)0) #endif #if ITTLOGLEVEL_WARNING <= ITTMAXLOGLEVEL #define ITTDWARNING(xx, ...) ITTDPRINT(xx, ##__VA_ARGS__) #else #define ITTDWARNING(xx, ...) ((void)0) #endif #if ITTLOGLEVEL_INFO <= ITTMAXLOGLEVEL #define ITTDINFO(xx, ...) ITTDPRINT(xx, ##__VA_ARGS__) #else #define ITTDINFO(xx, ...) ((void)0) #endif #ifdef ITTDEBUG #define ITTDCONDITIONLOG(condition, xx, ...) { if ((condition)) { \ ITTDPRINT(xx, ##__VA_ARGS__); \ } \ } ((void)0) #else #define ITTDCONDITIONLOG(condition, xx, ...) ((void)0) #endif #define ITTAssert(condition, ...) \ do { \ if (!(condition)) { \ [[NSAssertionHandler currentHandler] \ handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] \ file:[NSString stringWithUTF8String:__FILE__] \ lineNumber:__LINE__ \ description:__VA_ARGS__]; \ } \ } while(0) #define _po(o) DLOG(@"%@", (o)) #define _pn(o) DLOG(@"%d", (o)) #define _pf(o) DLOG(@"%f", (o)) #define _ps(o) DLOG(@"CGSize: {%.0f, %.0f}", (o).width, (o).height) #define _pr(o) DLOG(@"NSRect: {{%.0f, %.0f}, {%.0f, %.0f}}", (o).origin.x, (o).origin.x, (o).size.width, (o).size.height) #define DOBJ(obj) DLOG(@"%s: %@", #obj, [(obj) description]) #define MARK NSLog(@"\nMARK: %s, %d", __PRETTY_FUNCTION__, __LINE__)
#ifdef DEBUG //Debug模式 //... #else //釋出模式 //... //遮蔽NSLog #define NSLog(...) {}; #endif //------------------------------------Simulator/Device //區分模擬器和真機 #if TARGET_OS_IPHONE //iPhone Device #endif #if TARGET_IPHONE_SIMULATOR //iPhone Simulator #endif //------------------------------------ARC/no RAC //ARC #if __has_feature(objc_arc) //compiling with ARC #else // compiling without ARC #endif //Block typedef void(^VoidBlock)(); typedef BOOL(^BoolBlock)(); typedef int (^IntBlock) (); typedef id (^IDBlock) (); typedef void(^VoidBlock_int)(int); typedef BOOL(^BoolBlock_int)(int); typedef int (^IntBlock_int) (int); typedef id (^IDBlock_int) (int); typedef void(^VoidBlock_string)(NSString*); typedef BOOL(^BoolBlock_string)(NSString*); typedef int (^IntBlock_string) (NSString*); typedef id (^IDBlock_string) (NSString*); typedef void(^VoidBlock_id)(id); typedef BOOL(^BoolBlock_id)(id); typedef int (^IntBlock_id) (id); typedef id (^IDBlock_id) (id); //System #define PasteString(string) [[UIPasteboard generalPasteboard] setString:string]; #define PasteImage(image) [[UIPasteboard generalPasteboard] setImage:image]; //Image //可拉伸的圖片 #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] //file //讀取檔案的文字內容,預設編碼為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)]] //數學 #define PI 3.14159 //輸出frame(frame是結構體,沒法%@) #define LOGFRAME(f) NSLog(@"\nx:%f\ny:%f\nwidth:%f\nheight:%f\n",f.origin.x,f.origin.y,f.size.width,f.size.height) #define LOGBOOL(b) NSLog(@"%@",
[email protected]"YES":@"NO"); //彈出資訊 #define ALERT(msg) [[[UIAlertView alloc] initWithTitle:nil message:msg delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil] show] //App #define kApp ((AppDelegate *)[UIApplication sharedApplication].delegate) #define kNav ((AppDelegate *)[UIApplication sharedApplication].delegate.navigationController) //color #define RGB(r, g, b) [UIColor colorWithRed:((r) / 255.0) green:((g) / 255.0) blue:((b) / 255.0) alpha:1.0] #define RGBAlpha(r, g, b, a) [UIColor colorWithRed:((r) / 255.0) green:((g) / 255.0) blue:((b) / 255.0) alpha:(a)] #define HexRGB(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] #define HexRGBAlpha(rgbValue,a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:(a)] //轉換 #define I2S(number) [NSString stringWithFormat:@"%d",number] #define F2S(number) [NSString stringWithFormat:@"%f",number] #define DATE(stamp) [NSDate dateWithTimeIntervalSince1970:[stamp intValue]]; //裝置螢幕尺寸 #define kScreen_Height ([UIScreen mainScreen].bounds.size.height) #define kScreen_Width ([UIScreen mainScreen].bounds.size.width) #define kScreen_Frame (CGRectMake(0, 0 ,kScreen_Width,kScreen_Height)) #define kScreen_CenterX kScreen_Width/2 #define kScreen_CenterY kScreen_Height/2 //應用尺寸(不包括狀態列,通話時狀態列高度不是20,所以需要知道具體尺寸) #define kContent_Height ([UIScreen mainScreen].applicationFrame.size.height) #define kContent_Width ([UIScreen mainScreen].applicationFrame.size.width) #define kContent_Frame (CGRectMake(0, 0 ,kContent_Width,kContent_Height)) #define kContent_CenterX kContent_Width/2 #define kContent_CenterY kContent_Height/2 /* 類似九宮格的九個點 p1 --- p2 --- p3 | | | p4 --- p5 --- p6 | | | p7 --- p8 --- p9 */ #define kP1 CGPointMake(0 ,0) #define kP2 CGPointMake(kContent_Width/2 ,0) #define kP3 CGPointMake(kContent_Width ,0) #define kP4 CGPointMake(0 ,kContent_Height/2) #define kP5 CGPointMake(kContent_Width/2 ,kContent_Height/2) #define kP6 CGPointMake(kContent_Width ,kContent_Height/2) #define kP7 CGPointMake(0 ,kContent_Height) #define kP8 CGPointMake(kContent_Width/2 ,kContent_Height) #define kP9 CGPointMake(kContent_Width ,kContent_Height) //********************************************* //GCD #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) //Device #define isIOS4 ([[[UIDevice currentDevice] systemVersion] intValue]==4) #define isIOS5 ([[[UIDevice currentDevice] systemVersion] intValue]==5) #define isIOS6 ([[[UIDevice currentDevice] systemVersion] intValue]==6) #define isAfterIOS4 ([[[UIDevice currentDevice] systemVersion] intValue]>4) #define isAfterIOS5 ([[[UIDevice currentDevice] systemVersion] intValue]>5) #define isAfterIOS6 ([[[UIDevice currentDevice] systemVersion] intValue]>6) #define iOS ([[[UIDevice currentDevice] systemVersion] floatValue]) #define isRetina ([[UIScreen mainScreen] scale]==2) #define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO) #define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) //撥打電話 #define canTel ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel:"]]) #define tel(phoneNumber) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneNumber]]]) #define telprompt(phoneNumber) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt:%@",phoneNumber]]]) //開啟URL #define canOpenURL(appScheme) ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:appScheme]]) #define openURL(appScheme) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:appScheme]])
相關推薦
ios開發常用的巨集
轉載自 http://www.cocoachina.com/bbs/read.php?tid=137317&page=1 //use stringmake for NSString #define StringMake(fmt, ...) [NSString str
ios開發常用的宏
sso dex osi comm ignore scac va_arg pragma weakself 轉自 http://www.cocoachina.com/bbs/read.php?tid=1719540 #define NavigationBa
iOS開發常用宏定義
face 4.0 zone 定義 sel color type main def p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008400 } p.p2 { margin: 0.0p
ios開發-常用三方工具
helper alertview ability ive ref auto progress afnetwork work #菜單 pod ‘LGSideMenuController‘ # 刷新 pod ‘MJRefresh‘ # 網
2018 6年iOS開發常用的三方庫
上拉 res ios 開發 keyboard fresh 鍵盤 font network 開發一般APP必備三方庫,省力秘籍!!!本篇文章會經常更新最新常用的三方。 1.網絡請求庫 AFNetworking https://github.com/AFNetworking/A
iOS開發 常用的框架demo
總結了一些常用的demo,包括獲取驗證碼、AVPlayer、AFNetworking、Masonry、高仿微信、高仿網易、K線圖、折線圖、柱狀圖、手勢解鎖、TouchID、直播、動畫等,大家可以根據需要自取,大部分都是來自GitHub。 1、獲取驗證碼 http://
iOS開發之--巨集定義與const的區別及使用方法
巨集定義的常見用法: 定義一段程式碼,或指定字串抽成巨集。 const(常量): 當有字串常量的時候,蘋果推薦我們使用const,蘋果經常把常用的字串定義成const 巨集定義與const的區別: 編譯時刻:巨集是預編譯(編譯之前處理),const是編譯階段。 編
iOS開發常用的第三方類庫
轉自:https://blog.csdn.net/pleasecallmewhy/article/details/17149623 在iOS開發中不可避免的會用到一些第三方類庫,它們提供了很多實用的功能,使我們的開發變得更有效率;同時,也可以從它們的原始碼中學習到很多有用的東西。 Reach
ios開發常用第三方庫收集以及整理
1、RESideMenu 實現側邊欄選單 2、AFNetworking 實現網路通訊的第三方庫 3、一個有用的服務網站,提供各種JSON資料,包括天氣、電話號碼、身份證查詢等。。 4、Masony一個用來對VIEW進行佈局的三方庫 5、MBProgressHUD一個
iOS開發-常用第三方開源框架介紹(絕對夠你用了)
影象: 1.圖片瀏覽控制元件MWPhotoBrowser 實現了一個照片瀏覽器類似 iOS 自帶的相簿應用,可顯示來自手機的圖片或者是網路圖片,可自動從網路下載圖片並進行快取。可對圖片進行縮放等操作。 下載:https:
ios 開發常用技巧
1.TableView不顯示沒內容的Cell怎麼辦? self.tableView.tableFooterView = [[UIView alloc] init]; 2.自定義了leftBarbuttonItem左滑返回手勢失效了怎麼辦? self.naviga
iOS 開發常用的23種設計模式簡介
//聯絡人:石虎 QQ:1224614774 暱稱:嗡嘛呢叭咪哄 一、概念 設計模式主要分三個型別:建立型、結構型和行為型。 二、建立型有: 1.單例模式(Singlet
強烈推薦大家看這篇文章:iOS開發常用三方庫、外掛、知名部落格等等(特別有用)
Swift版本點選這裡歡迎加入交QQ流群: 594119878 使用方法:根據目錄關鍵字搜尋,記得包含@,以保證搜尋目錄關鍵字的唯一性。 引入評價機制:根據作者們的主觀評價,對庫是用"贊"、“很贊”、“非常贊”這3個評價伺候,便於大家在初次選擇庫時有一
iOS開發常用的加密方式介紹和使用
普通加密方法是講密碼進行加密後儲存到使用者偏好設定中鑰匙串是以明文形式儲存,但是不知道存放的具體位置 一. base64加密 base64 編碼是現代密碼學的基礎基本原理: 原本是 8個bit 一組表示資料,改為 6個bit一組表示資料,不足的部分補零,每 兩個0 用 一個 = 表示用base64 編碼之後
IOS開發常用命令
1 lldb命令 image list -o -f br s -a 0x10b52087d b bt c 2 符號翻譯命令 需要dSYM符號檔案,沒有則反彙編; 動態庫基地址為0;可執行檔案otool命令檢視。 atos -o ./xxx -l 0x0 -arch arm6
iOS開發之Runtime常用示例總結
開發一、構建Runtime測試用例本篇博客的內容是依托於實例的,所以我們在本篇博客中先構建我們的測試類,Runtime將會對該類進行相關的操作。下方就是本篇博客所涉及Demo的目錄,上面的RuntimeKit類是講Runtime常用的功能進行了簡單的封裝,而下方的TestClass以及相關的類目就是我們Run
iOS開發中常用的宏
tar lin iter standard ffi ant height same alt OC對象判斷是否為空? 字符串是否為空 #define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] ||
iOS開發基礎:OC數組對象NSArray的常用方法
indexof c語言 super main sset spa -- arr 初始 本文介紹了OC的數組對象的基本方法的使用: 因為OC的數組中存儲的為對象類型,所以我們可以新建一個Person類,通過Person生成對象進行操作。 其中Person.h中的代碼為: [o
iOS開發:常用的UIView控制元件——UILabel、UITextField、UIButton
前面幾篇文章已經對iOS開發中比較基本的幾個檔案進行了瞭解,今天主要學習StoryBoard檔案和幾個常見的UI控制元件。 Storyboard功能是在iOS5開始新增的功能,一種新技術的出現大多是為了彌補舊技術的不足,而在storyboard之前iOS 開發設計介面是使用nib檔案(xib
iOS開發之Xcode常用除錯技巧總結
轉載http://www.cocoachina.com/ios/20161102/17884.html 本文為投稿文章,作者:楊社兵 最近在面試,面試過程中問到了一些Xcode常用的除錯技巧問題。平常開發過程中用的還挺順手的,但你要突然讓我說,確實一臉懵逼。Debug的技巧