Agile development of iOS, common macro definition Summary

Source: Internet
Author: User

In iOS development, import macro definitions directly in the PCH file. When doing the project, directly to use, can greatly improve the development speed.
Here are some of the macro definitions that the individual summarizes. If you have other commonly used macro definitions, welcome to add. I will update this blog regularly .....

Don't say much, just go dry.

Add a # to the macro's arguments, and the macro's arguments are automatically converted to the C language string#define MRKEYPATH (Objc,keypath) @ (((void) Objc.keypath, #keyPath))//* * Load xib * **********************************************************************************#define LOADNIB (x) [[NSBundle Mainbundle] loadnibnamed:@ (x) owner:nil options:nil][0]//* * Sandbox path * **********************************************************************************#define Path_of_app_home nshomedirectory ()#define PATH_OF_TEMP nstemporarydirectory ()#define Path_of_document [Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES) OBJECTATINDEX:0]//* * DEBUG LOG * ********************************************************************************#ifdef DEBUG#define MRLOG (S, ...) NSLog (@ "<%@:(%d) >%@", [[NSString stringwithutf8string:__file__] lastpathcomponent], __line__, [NSString stringWithFormat: (s), # #__VA_ARGS__])#else#define MRLOG (S, ...)#endif//* * To get the current month and day seconds * ****************************************************************************#define CURRENTSEC [[Nscalendar Currentcalendar] component:nscalendarunitsecond fromdate:[nsdate Date]]#define Currentmin [[Nscalendar Currentcalendar] component:nscalendarunitminute fromdate:[nsdate Date]]#define Currenthour [[Nscalendar Currentcalendar] component:nscalendarunithour fromdate:[nsdate Date]]#define CURRENTDAY [[Nscalendar Currentcalendar] component:nscalendarunitday fromdate:[nsdate Date]]#define Currentmonth [[Nscalendar Currentcalendar] component:nscalendarunitmonth fromdate:[nsdate Date]]#define CURRENTYEAR [[Nscalendar Currentcalendar] component:nscalendarunityear fromdate:[nsdate Date]]//* * Angle converted to radians * *****************************************************************************************#define ANGEL (x) (x)/180.0 * M_PI//* FRAME (macro x, y, width, height) **************************************************************************APP Frame#define APPLICATION_FRAME [[UIScreen mainscreen] applicationframe]APP Frame Height&width#define App_frame_height [[UIScreen mainscreen] Applicationframe].size.height#define APP_FRAME_WIDTH [[UIScreen mainscreen] Applicationframe].size.widthMainscreen Height&width#define Main_screen_height [[UIScreen mainscreen] Bounds].size.height#define MAIN_SCREEN_WIDTH [[UIScreen mainscreen] Bounds].size.widthView coordinates (x, y) and width height (width,height)#define VIEWXPOS (v) (v). Frame.origin.x#define VIEWYPOS (v) (v). FRAME.ORIGIN.Y#define Viewwidth (v) (v). Frame.size.width#define Viewheight (v) (v). Frame.size.height#define MINFRAMEX (v) Cgrectgetminx ((v). Frame)#define Minframey (v) cgrectgetminy ((v). Frame)#define MIDFRAMEX (v) cgrectgetmidx ((v). Frame)#define Midframey (v) cgrectgetmidy ((v). Frame)#define MAXFRAMEX (v) Cgrectgetmaxx ((v). Frame)#define Maxframey (v) cgrectgetmaxy ((v). Frame)System control Default Height#define Kstatusbarheight (20.F)#define Ktopbarheight (44.F)#define Kbottombarheight (49.F)#define Kcelldefaultheight (44.F)#define Kenglishkeyboardheight (216.F)#define Kchinesekeyboardheight (252.F)/* *******************************************************************************************************************/#pragma mark-funtion method (macro methods)PNG JPG Picture Path#define GETIMAGEPATHFROMBUNDLE (NAME) [[NSBundle Mainbundle] pathforresource:[nsstring stringwithutf8string:name ] Oftype:nil]#define GETEXTPATHFROMBUNDLE (name, EXT) [[NSBundle Mainbundle] Pathforresource: (name) OfType: (EXT)]Color (RGB)#define RgbColor (R, G, b) [Uicolor colorwithred: (r)/255.0f Green: (g)/255.0f Blue: (b)/255.0f Alpha:1]#define RgbColor (R, G, B, a) [Uicolor colorwithred: (r)/255.0f Green: (g)/255.0f Blue: (b)/255.0f Alpha: (a)]#define Randomcolor [Uicolor colorwithred:arc4random_uniform ()/255.0 Green:arc4random_uniform (256)/255.0 Blue:arc4random_uniform ()/255.0 alpha:1]View Fillet and border#define Viewborderradius (View, Radius, Width, Color) \[View.layer Setcornerradius: (Radius)];\[View.layer setmaskstobounds:yes];\[View.layer setborderwidth: (Width)];\[View.layer setbordercolor:[color Cgcolor]]Current version#define FSYSTEMVERSION ([[[Uidevice Currentdevice] systemversion] floatvalue])#define DSYSTEMVERSION ([[[Uidevice Currentdevice] systemversion] doublevalue])#define Ssystemversion ([[Uidevice Currentdevice] systemversion])Current language#define CURRENTLANGUAGE ([[Nslocale preferredlanguages] objectatindex:0])Whether the Retina screen#define Isretina ([UIScreen instancesrespondtoselector: @selector (currentmode)]? \cgsizeequaltosize (Cgsizemake (640, 960), \[[UIScreen mainscreen] currentmode].size): \NO)Whether IPhone5#define ISIPHONE5 ([UIScreen instancesrespondtoselector: @selector (currentmode)]? \cgsizeequaltosize (Cgsizemake (640, 1136), \[[UIScreen mainscreen] currentmode].size): \NO)whether ipad#define ISPAD (ui_user_interface_idiom () = = Uiuserinterfaceidiompad)Uiview-viewwithtag#define VIEWWITHTAG (_object, _tag) [_object viewwithtag: _tag]Localized string/* * Nslocalizedstring macro is actually looking for the resource filename "localizable.strings" (parameter: Key + comment) in the current bundle */#define LOCALSTRING (x, ...) Nslocalizedstring (x, nil)/* * Nslocalizedstringfromtable macro is actually looking for the resource filename "xxx.strings" (Parameter: Key + file name + comment) in the current bundle */#define APPLOCALSTRING (x, ...) Nslocalizedstringfromtable (x, @ "Somename", nil)

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Agile development of iOS, common macro definition Summary

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.