IOS Common macro Definitions
Last Update:2015-12-23
Source: Internet
Author: User
<span id="Label3"></p><p>#ifndef Macrodefinition_h<br>#define Macrodefinition_h<br><br>-------------------get the device size-------------------------<br>NavBar Height<br>#define Navigationbar_height 44<br><br>Get screen width, height<br>#define Screen_width ([uiscreen Mainscreen].bounds.size.width)<br>#define Screen_height ([uiscreen Mainscreen].bounds.size.height)<br><br>-------------------get the device size-------------------------<br><br><br>-------------------print log-------------------------<br>Print log in DEBUG mode, when moving forward<br>#ifdef DEBUG<br># define DLOG (fmt, ...) NSLog (@ "%s [line%d]" fmt), __pretty_function__, __line__, # #__VA_ARGS__);<br>#else<br># define DLOG (...)<br>#endif<br><br><br>To rewrite the print log and the current number of lines in Nslog,debug mode<br>#if DEBUG<br>#define NSLOG (FORMAT, ...) fprintf (stderr, "\nfunction:%s line:%d content:%s\n", __function__, __line__, [nsstring stringwithformat:format, # #__VA_ARGS__] utf8string]);<br>#else<br>#define NSLOG (FORMAT, ...) Nil<br>#endif<br><br>Print log in DEBUG mode, current line and pop up a warning<br>#ifdef DEBUG<br># 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]; }<br>#else<br># define Ulog (...)<br>#endif<br><br><br>#define Ittdebug<br>#define ITTLOGLEVEL_INFO 10<br>#define Ittloglevel_warning 3<br>#define ITTLOGLEVEL_ERROR 1<br><br>#ifndef Ittmaxloglevel<br><br>#ifdef DEBUG<br>#define Ittmaxloglevel Ittloglevel_info<br>#else<br>#define Ittmaxloglevel Ittloglevel_error<br>#endif<br><br>#endif<br><br>The general purpose Logger. This ignores logging levels.<br>#ifdef Ittdebug<br>#define Ittdprint (xx, ...) NSLog (@ "%s (%d):" xx, __pretty_function__, __line__, # #__VA_ARGS__)<br>#else<br>#define Ittdprint (xx, ...) ((void) 0)<br>#endif<br><br>Print the name of the current method<br>#define Ittdprintmethodname () ittdprint (@ "%s", __pretty_function__)<br><br>Log-level based Logging Macros.<br>#if ittloglevel_error <= Ittmaxloglevel<br>#define ITTDERROR (xx, ...) Ittdprint (xx, # #__VA_ARGS__)<br>#else<br>#define ITTDERROR (xx, ...) ((void) 0)<br>#endif<br><br>#if ittloglevel_warning <= Ittmaxloglevel<br>#define Ittdwarning (xx, ...) Ittdprint (xx, # #__VA_ARGS__)<br>#else<br>#define Ittdwarning (xx, ...) ((void) 0)<br>#endif<br><br>#if ittloglevel_info <= Ittmaxloglevel<br>#define ITTDINFO (xx, ...) Ittdprint (xx, # #__VA_ARGS__)<br>#else<br>#define ITTDINFO (xx, ...) ((void) 0)<br>#endif<br><br>#ifdef Ittdebug<br>#define Ittdconditionlog (condition, xx, ...) {if ((CONDITION)) {\<br>Ittdprint (xx, # #__VA_ARGS__); \<br>} \<br>} ((void) 0)<br>#else<br>#define Ittdconditionlog (condition, xx, ...) ((void) 0)<br>#endif<br><br>#define Ittassert (condition, ...) \<br>Do {\<br>If (! ( CONDITION)) {\<br>[nsassertionhandler currenthandler] \<br>Handlefailureinfunction:[nsstring stringwithutf8string:__pretty_function__] \<br>File:[nsstring stringwithutf8string:__file__] \<br>LINENUMBER:__LINE__ \<br>description:__va_args__]; \<br>} \<br>} while (0)<br><br>---------------------print log--------------------------<br><br><br>----------------------system----------------------------<br><br>whether ipad<br>#define ISPAD (ui_user_interface_idiom () = = Uiuserinterfaceidiompad)<br>whether ipad<br>#define SomeThing (ui_user_interface_idiom () = = uiuserinterfaceidiompad)? Ipad:iphone<br><br>Get System version<br>#define Ios_version [[uidevice currentdevice] systemversion] floatvalue]<br>#define Currentsystemversion [uidevice currentdevice] systemversion]<br><br>Get the current language<br>#define Currentlanguage ([nslocale preferredlanguages] objectatindex:0])<br><br>Determine if the retina screen, whether the device Is%fhone 5, is an ipad<br>#define Isretina ([uiscreen instancesrespondtoselector: @selector (currentmode)]? Cgsizeequaltosize (cgsizemake (640, 960), [uiscreen mainscreen] currentmode].size): NO)<br>#define IPHONE5 ([uiscreen instancesrespondtoselector: @selector (currentmode)]? Cgsizeequaltosize (cgsizemake (640, 1136), [uiscreen mainscreen] currentmode].size): NO)<br>#define ISPAD (ui_user_interface_idiom () = = Uiuserinterfaceidiompad)<br><br>Judging the Device's operating system is not iOS7<br>#define IOS7 ([[uidevice currentdevice].systemversion doublevalue] >= 7.0]<br><br>Determine if the current device is iphone5<br>#define KSCREENIPHONE5 (([uiscreen mainscreen] bounds].size.height) >=568)<br><br>Gets the height of the current screen<br>#define Kmainscreenheight ([uiscreen Mainscreen].applicationframe.size.height)<br><br>Gets the width of the current screen<br>#define Kmainscreenwidth ([uiscreen Mainscreen].applicationframe.size.width)<br><br><br><br>Define a define function<br>#define Tt_release_cf_safely (__ref) {if (nil! = (__ref)) {cfrelease (__ref); __ref = nil;}}<br><br>Judging whether it's a real machine or a simulator<br>#if Target_os_iphone<br>IPhone Device<br>#endif<br> <br>#if Target_iphone_simulator<br>IPhone Simulator<br>#endif<br><br>Check the system version<br>#define SYSTEM_VERSION_EQUAL_TO (v) ([[uidevice currentdevice] systemversion] compare:v options:nsnumericsearch] = = Nsorderedsame)<br>#define System_version_greater_than (v) ([[uidevice currentdevice] systemversion] compare:v options:nsnumericsearch] = = Nsordereddescending)<br>#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO (v) ([[uidevice currentdevice] systemversion] compare:v options: nsnumericsearch]! = Nsorderedascending)<br>#define System_version_less_than (v) ([[uidevice currentdevice] systemversion] compare:v options:nsnumericsearch] = = Nsorderedascending)<br>#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO (v) ([[uidevice currentdevice] systemversion] compare:v options: nsnumericsearch]! = Nsordereddescending)<br><br><br>----------------------system----------------------------<br><br><br>----------------------memory----------------------------<br><br>Use arc and do not use arc<br>#if __has_feature (objc_arc)<br>Compiling with ARC<br>#else<br>Compiling without ARC<br>#endif<br><br>#pragma mark-common functions<br>#define Release_safely (__pointer) {[__pointer RELEASE]; __pointer = nil;}<br><br>Releasing an Object<br>#define Safe_delete (p) if (p) {[p release], p = nil;}<br><br>#define Safe_release (x) [x Release];x=nil<br><br><br><br>----------------------memory----------------------------<br><br><br>----------------------pictures----------------------------<br><br>Reading local Pictures<br>#define LoadImage (file,ext) [UIImage imagewithcontentsoffile:[nsbundle mainbundle]pathforresource:file ofType:ext]<br><br>Defining UIImage Objects<br>#define IMAGE (A) [UIImage imagewithcontentsoffile:[nsbundle mainbundle] pathforresource:a oftype:nil]<br><br>Defining UIImage Objects<br>#define IMAGENAMED (_pointer) [UIImage imagenamed:[uiutil imagename:_pointer]<br><br>The first two macro definitions are recommended, with higher performance than the latter<br>----------------------pictures----------------------------<br><br><br><br>----------------------color class---------------------------<br>RGB Color Conversion (16 binary->10)<br>#define UICOLORFROMRGB (rgbvalue) [uicolor colorwithred: ((float) ((rgbvalue & 0xFF0000) >>))/255.0 green: (( Float) ((rgbvalue & 0xff00) >> 8)/255.0 blue: ((float) (rgbvalue & 0xFF))/255.0 alpha:1.0]<br><br>Color settings with RGBA<br>#define COLOR (R, G, B, A) [uicolor colorwithred:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]<br><br>Get RGB color<br>#define RGBA (r,g,b,a) [uicolor colorwithred:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]<br>#define RGB (r,g,b) RGBA (r,g,b,1.0f)<br><br>Background color<br>#define Background_color [uicolor colorwithred:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0]<br><br>Clear background color<br>#define Clearcolor [uicolor clearcolor]<br><br>#pragma mark-color functions<br>#define RGBCOLOR (r,g,b) [uicolor colorwithred: (r)/255.0f green: (g)/255.0f blue: (b)/255.0f alpha:1]<br>#define Rgbacolor (r,g,b,a) [uicolor colorwithred: (r)/255.0f green: (g)/255.0f blue: (b)/255.0f alpha: (a)]<br><br>----------------------color class--------------------------<br><br><br><br>----------------------other----------------------------<br><br>Definition of Founder's bold and simplified body<br>#define FONT (F) [uifont fontwithname:@ "fzhtjw--gb1-0" size:f]<br><br> <br>Define an API<br>#define APIURL @ "http://xxxxx/"<br>Login API<br>#define Apilogin [apiurl stringbyappendingstring:@ "Login"]<br><br>Set the Tag property of the View<br>#define VIEWWITHTAG (_object, _tag) [_object viewwithtag: _tag]<br>Localization of programs, referencing internationalized files<br>#define Mylocal (x, ...) Nslocalizedstring (x, Nil)<br><br>G-c-d<br>#define BACK (block) dispatch_async (dispatch_get_global_queue (dispatch_queue_priority_default, 0), Block)<br>#define MAIN (block) dispatch_async (dispatch_get_main_queue (), Block)<br><br>Nsuserdefaults instantiation<br>#define User_default [nsuserdefaults standarduserdefaults]<br><br><br>Get radians from angle get angle<br>#define Degreestoradian (x) (M_PI * (x)/180.0)<br>#define Radiantodegrees (radian) (radian*180.0)/(m_pi)<br><br><br><br>Singleton a class<br>#define Synthesize_singleton_for_class (classname) \<br>\<br>static classname *shared# #classname = nil; \<br>\<br>+ (classname *) shared# #classname \<br>{ \<br>@synchronized (self) \<br>{ \<br>If (shared# #classname = = nil) \<br>{ \<br>shared# #classname = [self alloc] init]; \<br>} \<br>} \<br>\<br>return shared# #classname; \<br>} \<br>\<br>+ (id) allocwithzone: (nszone *) zone \<br>{ \<br>@synchronized (self) \<br>{ \<br>If (shared# #classname = = nil) \<br>{ \<br>shared# #classname = [super allocwithzone:zone]; \<br>return shared# #classname; \<br>} \<br>} \<br>\<br>Return nil; \<br>} \<br>\<br>-(id) copywithzone: (nszone *) zone \<br>{ \<br>Return self; \<br>}<br><br><br><br>#endif</p><p><p>IOS Common macro Definitions</p></p></span>