Usage and specification of IOS macro definitions

Source: Internet
Author: User

Macro definitions are used in many ways, such as defining heights, judging iOS systems, tool classes, and documentation such as file paths and server-side API interfaces. In order to quickly locate and understand the function of a macro, it is best to put it in a specific header file when defined

define a macro for a dimension classDimensMacros.h//Status Bar Height#defineStatus_bar_height 20//NavBar Height#defineNavigation_bar_height 44//status bar + navigation bar height#defineStatus_and_navigation_height ((status_bar_height) + (navigation_bar_height))//Screen rect#defineScreen_rect ([UIScreen mainscreen].bounds)#defineScreen_width ([UIScreen mainscreen].bounds.size.width)#defineScreen_height ([UIScreen mainscreen].bounds.size.height)#defineContent_height (Screen_height-navigation_bar_height-status_bar_height)//Screen Resolution#defineScreen_resolution (Screen_width * screen_height * ([UIScreen Mainscreen].scale))//Advertisement Height#defineBanner_height 215#defineStylepage_height 21#defineSmalltv_height 77#defineSmalltv_width 110#defineFollow_height 220#defineSubchannel_height 622. Define macros for the sandbox catalog filePathMacros.h//file directory#defineKpathtemp Nstemporarydirectory ()#definekpathdocument [Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES) objectAtIndex 700#defineKpathcache [Nssearchpathfordirectoriesindomains (Nscachesdirectory, Nsuserdomainmask, YES) objectAtIndex:0 ]#defineKpathsearch [kpathdocument stringbyappendingpathcomponent:@ "Search.plist"]#defineKpathmagazine [kpathdocument stringbyappendingpathcomponent:@ "Magazine"]#defineKpathdownloadedmgzs [Kpathmagazine stringbyappendingpathcomponent:@ "Downloadedmgz.plist"]#defineKpathdownloadurls [Kpathmagazine stringbyappendingpathcomponent:@ "Downloadurls.plist"]#definekpathoperation [Kpathmagazine stringbyappendingpathcomponent:@ "Operation.plist"]#defineKpathsplashscreen [Kpathcache stringbyappendingpathcomponent:@ "SplashScreen"]#endif3. Macros for tool classesUtilsMacros.h//Log utils Marco #defineALog (FMT, ...) NSLog (@ "%s [line%d]" FMT), __pretty_function__, __line__, # #__VA_ARGS__);#ifdefDEBUG#defineDLog (FMT, ...) NSLog (@ "%s [line%d]" FMT), __pretty_function__, __line__, # #__VA_ARGS__);#else#defineDLog (...)#endif #ifdefDEBUG#defineUlog (...)//#define ULOG (FMT, ...) {Uialertview *alert = [[Uialertview alloc] initwithtitle:[nsstring stringwithformat:@ "%s\n [line%d]", __pretty_functio n__, __line__] message:[nsstring stringwithformat:fmt, # #__VA_ARGS__] delegate:nil cancelbuttontitle:@ "OK" Otherbuttontitles:nil]; [Alert show]; }#else#defineUlog (...)#endif  //System version Utils #defineSystem_version_equal_to (v) ([[[Uidevice Currentdevice] systemversion] compare:v Options:nsnumericsearch] = = Nsorderedsame)#defineSystem_version_greater_than (v) ([[[Uidevice Currentdevice] systemversion] compare:v Options:nsnumericsearch] = = nsordereddescending)#defineSystem_version_greater_than_or_equal_to (v) ([[[Uidevice Currentdevice] systemversion] compare:v options: Nsnumericsearch]! = nsorderedascending)#defineSystem_version_less_than (v) ([[[Uidevice Currentdevice] systemversion] compare:v Options:nsnumericsearch] = = nsorderedascending)#defineSystem_version_less_than_or_equal_to (v) ([[[Uidevice Currentdevice] systemversion] compare:v options: Nsnumericsearch]! = nsordereddescending)//Get RGB color#defineRGBA (r,g,b,a) [Uicolor colorwithred:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]#defineRGB (r,g,b) RGBA (r,g,b,1.0f)#defineIsportrait ([uiapplication sharedapplication].statusbarorientation = = Uiinterfaceorientationportrait | | [UIApplication sharedapplication].statusbarorientation = = Uiinterfaceorientationportraitupsidedown)#defineIsnilornull (_ref) (((_ref) = nil) | | ([(_REF) isequal:[nsnull Null]]))//Angle to radians#defineDegrees_to_radians (d) (d * m_pi/180)//iOS version greater than or equal to 7.0#defineIos7_or_later system_version_greater_than_or_equal_to (@ "7.0")//iOS version greater than or equal to 8.0#defineIos8_or_later system_version_greater_than_or_equal_to (@ "8.0")//IOS6, the starting height of the view in the navigation VC#defineYh_height (ios7_or_later? 64:0)//get the system time stamp#defineGetcurenttime [NSString stringwithformat:@ "%ld", (long) [[NSDate Date] timeIntervalSince1970]]4. Notification of notification related macrosNotificationMacros.h//system Notification Definition #defineTncancelfavoriteproductnotification @ "Tncancelfavoriteproductnotification"//when you cancel a collection#defineTnmarkfavoriteproductnotification @ "Tnmarkfavoriteproductnotification"//when you mark a collection #defineknotficationdownloadprogresschanged @ "Knotficationdownloadprogresschanged"//Download Progress Changes#defineKnotificationpausedownload @ "Knotificationpausedownload"//Pause Download#defineKnotificationstartdownload @ "Knotificationstartdownload"//Start Download #defineknotificationdownloadsuccess @ "Knotificationdownloadsuccess"//Download Successful#defineknotificationdownloadfailed @ "knotificationdownloadfailed"//Download Failed#defineKnotificationdownloadnewmagazine @ "Knotificationdownloadnewmagazine"server-side API interface MacrosAPIStringMacros.h////////////////////////////////////////////////////////////////////////////////////////////////////Interface Name Correlation #ifdefDEBUG//Test API in debug State#defineapi_base_url_string @ "http://boys.test.companydomain.com/api/" #else//on-line API in release status#defineapi_base_url_string @ "http://www.companydomain.com/api/" #endif //Interface#defineGet_content_detail @ "Channel/getcontentdetail"//get content details (including previous and next) #defineGet_comment_list @ "Comment/getcommentlist"//get a list of comments #defineComment_login @ "Comment/login"//get a list of comments #defineComment_publish @ "Comment/publish"//Post a comment #defineComment_delete @ "Comment/delcomment"//Delete Comments #defineLoginout @ "Common/logout"//Log OutThere are many other types of macros that are not listed here

Usage and specification of IOS macro definitions

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.