http://my.oschina.net/leejan97/blog/354904
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 the macro can quickly locate and understand its function, we better in the definition of the time to put it into a specific header file, the following I would like to introduce some commonly used macros to classify, sub-file definition, I hope to be helpful.
Define a macro for a dimension class
DimensMacros.h
Status bar Height
#define Status_bar_height 20
NavBar Height
#define Navigation_bar_height 44
status bar + navigation bar height
#define Status_and_navigation_height ((status_bar_height) + (navigation_bar_height))
Screen rect
#define SCREEN_RECT ([UIScreen mainscreen].bounds)
#define SCREEN_WIDTH ([UIScreen mainscreen].bounds.size.width)
#define Screen_height ([UIScreen mainscreen].bounds.size.height)
#define Content_height (Screen_height-navigation_bar_height-status_bar_height)
Screen resolution
#define Screen_resolution (Screen_width * screen_height * ([UIScreen Mainscreen].scale))
Advertisement height
#define Banner_height 215
#define Stylepage_height 21
#define Smalltv_height 77
#define SMALLTV_WIDTH 110
#define Follow_height 220
#define Subchannel_height 62
2. Define a macro for the sandbox catalog file
PathMacros.h
File directory
#define KPATHTEMP nstemporarydirectory ()
#define Kpathdocument [Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES) objec TATINDEX:0]
#define Kpathcache [Nssearchpathfordirectoriesindomains (Nscachesdirectory, Nsuserdomainmask, YES) ObjectA TINDEX:0]
#define Kpathsearch [kpathdocument stringbyappendingpathcomponent:@ "Search.plist"]
#define Kpathmagazine [kpathdocument stringbyappendingpathcomponent:@ "Magazine"]
#define KPATHDOWNLOADEDMGZS [Kpathmagazine stringbyappendingpathcomponent:@ "Downloadedmgz.plist"]
#define KPATHDOWNLOADURLS [Kpathmagazine stringbyappendingpathcomponent:@ "Downloadurls.plist"]
#define Kpathoperation [Kpathmagazine stringbyappendingpathcomponent:@ "Operation.plist"]
#define Kpathsplashscreen [Kpathcache stringbyappendingpathcomponent:@ "SplashScreen"]
#endif
3. Macros for tool classes
UtilsMacros.h
Log Utils Marco
#define ALOG (FMT, ...) NSLog (@ "%s [line%d]" FMT), __pretty_function__, __line__, # #__VA_ARGS__);
#ifdef DEBUG
#define DLOG (FMT, ...) NSLog (@ "%s [line%d]" FMT), __pretty_function__, __line__, # #__VA_ARGS__);
#else
#define DLOG (...)
#endif
#ifdef DEBUG
#define ULOG (...)
#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
#define ULOG (...)
#endif
System version Utils
#define SYSTEM_VERSION_EQUAL_TO (v) ([[[Uidevice Currentdevice] systemversion] compare:v options:nsnumeric Search] = = nsorderedsame)
#define System_version_greater_than (v) ([[[Uidevice Currentdevice] systemversion] compare:v options:nsnumeric Search] = = nsordereddescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO (v) ([[[Uidevice Currentdevice] systemversion] compare:v options: Nsnumericsearch]! = nsorderedascending)
#define System_version_less_than (v) ([[[Uidevice Currentdevice] systemversion] compare:v options:nsnumeric Search] = = nsorderedascending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO (v) ([[[Uidevice Currentdevice] systemversion] compare:v options: Nsnumericsearch]! = nsordereddescending)
Get RGB color
#define RGBA (r,g,b,a) [Uicolor colorwithred:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define RGB (r,g,b) RGBA (r,g,b,1.0f)
#define ISPORTRAIT ([uiapplication sharedapplication].statusbarorientation = = Uiinterfaceorientationportrait | | [UIApplication sharedapplication].statusbarorientation = = Uiinterfaceorientationportraitupsidedown)
#define ISNILORNULL (_ref) (((_ref) = nil) | | ([(_REF) isequal:[nsnull Null]]))
Angle to radians
#define Degrees_to_radians (d) (d * m_pi/180)
iOS version greater than or equal to 7.0
#define Ios7_or_later system_version_greater_than_or_equal_to (@ "7.0")
iOS version greater than or equal to 8.0
#define Ios8_or_later system_version_greater_than_or_equal_to (@ "8.0")
IOS6, the starting height of the view in the navigation VC
#define Yh_height (ios7_or_later? 64:0)
Get the system time stamp
#define Getcurenttime [NSString stringwithformat:@ "%ld", (long) [[NSDate Date] timeIntervalSince1970]]
4. Notification of notification related macros
NotificationMacros.h
System notification Definition
#define Tncancelfavoriteproductnotification @ "tncancelfavoriteproductnotification"//Cancel Collection
#define Tnmarkfavoriteproductnotification @ "tnmarkfavoriteproductnotification"//Tag Collection
#define Knotficationdownloadprogresschanged @ "knotficationdownloadprogresschanged"//Download Progress changes
#define KNOTIFICATIONPAUSEDOWNLOAD @ "Knotificationpausedownload"//Pause Download
#define KNOTIFICATIONSTARTDOWNLOAD @ "Knotificationstartdownload"//Start download
#define Knotificationdownloadsuccess @ "knotificationdownloadsuccess"//Download successful
#define KNOTIFICATIONDOWNLOADFAILED @ "knotificationdownloadfailed"//Download failed
#define Knotificationdownloadnewmagazine @ "Knotificationdownloadnewmagazine"
Server-side API interface macros
APIStringMacros.h
//////////////////////////////////////////////////////////////////////////////////////////////////
Interface Name Correlation
#ifdef DEBUG
Test API in Debug state
#define Api_base_url_string @ "http://boys.test.companydomain.com/api/"
#else
On-line API in release status
#define Api_base_url_string @ "http://www.companydomain.com/api/"
#endif
Interface
#define Get_content_detail @ "Channel/getcontentdetail"//Get content details (including previous and next)
#define Get_comment_list @ "comment/getcommentlist"//Get a list of comments
#define Comment_login @ "Comment/login"//Get a list of comments
#define Comment_publish @ "Comment/publish"//post comments
#define COMMENT_DELETE @ "comment/delcomment"//delete comments
#define LOGINOUT @ "Common/logout"//Logout
There are many other types of macros that are not listed here
Create an import of all macros related files Macros.h
Macros.h
#import "UtilsMacros.h"
#import "APIStringMacros.h"
#import "DimensMacros.h"
#import "NotificationMacros.h"
#import "SharePlatformMacros.h"
#import "StringMacros.h"
#import "UserBehaviorMacros.h"
#import "PathMacros.h"
In the PCH file for the Xcode project, import the Macros.h file
Xcodeprojectname-prefix.pch
#ifdef __objc__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "Macros.h"
#endif
Usage and specification of IOS macro definitions