The macro definition of the specification in IOS development, the basic common macro definition organizes the collection. Share to everyone!

Source: Internet
Author: User

1 #ifndef Macrodefinition_h2 #defineMacrodefinition_h3 //appdelegate4  5 #defineAppdelegate [(appdelegate*) [uiapplication Sharedapplication] delegate]6 //----------------------System device-related----------------------------7 //Get device screen size8 #defineScreen_width ([UIScreen mainscreen].bounds.size.width)9 #defineScreen_height ([UIScreen mainscreen].bounds.size.height)//Application DimensionsTen #defineapp_width [[UIScreen mainscreen]applicationframe].size.width One #defineapp_height [[UIScreen mainscreen]applicationframe].size.height A //Get System version - #defineios_version [[[Uidevice Currentdevice] systemversion] floatvalue] - #definecurrentsystemversion [[Uidevice Currentdevice] systemversion] the #defineIsIOS4 ([[[Uidevice Currentdevice] systemversion] intvalue]==4) - #defineIsIOS5 ([[[Uidevice Currentdevice] systemversion] intvalue]==5) - #defineIsIOS6 ([[[Uidevice Currentdevice] systemversion] intvalue]==6) - #defineIsAfterIOS4 ([[[Uidevice Currentdevice] systemversion] intvalue]>4) + #defineIsAfterIOS5 ([[[Uidevice Currentdevice] systemversion] intvalue]>5) - #defineIsAfterIOS6 ([[[Uidevice Currentdevice] systemversion] intvalue]>6) + //get the current language A #defineCurrentlanguage ([[Nslocale preferredlanguages] objectatindex:0]) at   - //determine if the retina screen, whether the device is%fhone 5, is an ipad - #defineIsretina ([UIScreen instancesrespondtoselector: @selector (currentmode)]? Cgsizeequaltosize (Cgsizemake (640, 960), [[UIScreen Mainscreen] currentmode].size): NO) - #defineIPhone5 ([UIScreen instancesrespondtoselector: @selector (currentmode)]? Cgsizeequaltosize (Cgsizemake (640, 1136), [[UIScreen Mainscreen] currentmode].size): NO) - #defineIspad (ui_user_interface_idiom () = = Uiuserinterfaceidiompad) - //Judging whether it's a real machine or a simulator in #ifTarget_os_iphone - //IPhone Device to #endif + #ifTarget_iphone_simulator - //IPhone Simulator the #endif * //----------------------System device-related---------------------------- $  Panax Notoginseng //----------------------Memory-related---------------------------- - //use arc and do not use arc the #if__has_feature (OBJC_ARC) + //Compiling with ARC A #else the //Compiling without ARC + #endif - //releasing an object $ #defineSafe_delete (P) if (p) {[P release], p = nil;} $ #defineSafe_release (x) [x Release];x=nil - //----------------------Memory-related---------------------------- -   the //----------------------Pictures related to---------------------------- - //reading Local picturesWuyi #defineLoadImage (File,ext) [UIImage imagewithcontentsoffile:[[nsbundle mainbundle]pathforresource:file OfType:ext] the //Defining UIImage Objects - #defineIMAGE (A) [UIImage imagewithcontentsoffile:[[nsbundle Mainbundle] pathforresource:a Oftype:nil] Wu //Defining UIImage Objects - #defineImagenamed (_pointer) [UIImage Imagenamed:_pointer] About //stretchable Pictures $ #defineResizableimage (Name,top,left,bottom,right) [[UIImage Imagenamed:name] Resizableimagewithcapinsets: Uiedgeinsetsmake (Top,left,bottom,right)] - #defineResizableimagewithmode (Name,top,left,bottom,right,mode) [[UIImage Imagenamed:name] Resizableimagewithcapinsets: Uiedgeinsetsmake (top,left,bottom,right) Resizingmode:mode] - //The first two macro definitions are recommended, with higher performance than the latter - //----------------------Pictures related to---------------------------- A   + //----------------------Color-related--------------------------- the //RGB color conversion (16 binary->10) - #defineUicolorfromrgb (rgbvalue) [Uicolor colorwithred: ((float) ((Rgbvalue & 0xFF0000) >>))/255.0 Green: ((float) ( (Rgbvalue & 0xff00) >> 8)/255.0 Blue: ((float) (Rgbvalue & 0xFF))/255.0 alpha:1.0] $ //Get RGB color the #defineRGBA (r,g,b,a) [Uicolor colorwithred:r/255.0f green:g/255.0f blue:b/255.0f alpha:a] the #defineRGB (r,g,b) RGBA (r,g,b,1.0f) the //Background Color the #defineBackground_color [Uicolor colorwithred:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0] - //Clear Background color in #defineClearcolor [Uicolor Clearcolor] the //----------------------Color-related-------------------------- the   About //----------------------Other---------------------------- the //definition of Founder's bold and simplified body the #defineFONT (F) [Uifont fontwithname:@ "fzhtjw--gb1-0" size:f] the //file + //reads the text content of the file, the default encoding is UTF-8 - #defineFilestring (Name,ext) [[NSString alloc] Initwithcontentsoffile:[[nsbundle Mainbundle] Pathforresource: (name) OfT ype: (EXT)] encoding:nsutf8stringencoding Error:nil] the #defineFiledictionary (Name,ext) [[Nsdictionary alloc] Initwithcontentsoffile:[[nsbundle Mainbundle] PathForResource: (name) OfType: (EXT)]]Bayi #defineFilearray (Name,ext) [[Nsarray alloc] Initwithcontentsoffile:[[nsbundle Mainbundle] Pathforresource: (name) ofTy PE: (EXT)]] the //g-c-d the #defineBack (block) Dispatch_async (dispatch_get_global_queue (dispatch_queue_priority_default, 0), block) - #defineMAIN (Block) Dispatch_async (Dispatch_get_main_queue (), block) - //Alert the #defineALERT (msg) [[[Uialertview alloc] initwithtitle:nil message:msg delegate:nil cancelbuttontitle:@ "OK" otherbuttontitles : nil] show] the   the //get radians from angle get angle the #defineDegreestoradian (x) (M_PI * (x)/180.0) - #defineRadiantodegrees (Radian) (radian*180.0)/(M_PI) the //----------------------Other------------------------------- the   the //----------------------View-related----------------------------94 //set the text or picture you want to paste the #definePastestring (String) [[Uipasteboard Generalpasteboard] setstring:string]; the #definePasteimage (image) [[Uipasteboard Generalpasteboard] setimage:image]; the  98 //gets the x, y coordinate point of the left top of the view About #defineView_tx (view) (view.frame.origin.x) - #defineView_ty (view) (VIEW.FRAME.ORIGIN.Y)101  102 //get the x, y coordinate point of the right bottom of the view103 #defineVIEW_BX (view) (view.frame.origin.x + view.frame.size.width)104 #defineView_by (view) (VIEW.FRAME.ORIGIN.Y + view.frame.size.height) the  106 //get the dimensions of the view: width, height107 #defineView_w (view) (View.frame.size.width)108 #defineView_h (view) (View.frame.size.height)109 //get the x, y coordinate point of frame the #defineFrame_tx (frame) (frame.origin.x)111 #defineFrame_ty (frame) (FRAME.ORIGIN.Y) the //get the frame width, height113 #defineFrame_w (frame) (frame.size.width) the #defineFrame_h (frame) (frame.size.height) the //----------------------View-related---------------------------- the  117 //---------------------Print Log--------------------------118 //print Log in debug mode, current line, function name119 #ifDEBUG - #defineDLog (FORMAT, ...) fprintf (stderr, "\nfunction:%s line:%d content:%s\n", __function__, __line__, [[NSString Stringwithformat:format, # #__VA_ARGS__] utf8string]);121 #else122 #defineNSLog (FORMAT, ...) nil123 #endif124 //Debug mode print log, current line, function name and pop up a warning the #ifdefDEBUG126# define Wdlog (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]; }127 #else - # define NSLOG (...)129 #endif the //Print Frame131 #defineLogframe (frame) NSLog (@ "frame[x=%.1f,y=%.1f,w=%.1f,h=%.1f", Frame.origin.x,frame.origin.y,frame.size.width, Frame.size.height) the //Print Point133 #defineLogpoint (point) NSLog (@ "point[x=%.1f,y=%.1f]", POINT.X,POINT.Y)134 //---------------------Print Log--------------------------135 #endif

The macro definition of the specification in IOS development, the basic common macro definition organizes the collection. Share to everyone!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.