IOS agile development path, commonly used macro definition summary, ios path
During iOS development, the macro definition is directly imported into the pch file. It can be used directly during project creation to greatly improve the development speed.
The following are some macro definitions I have summarized. If you have other commonly used macro definitions, please add them. I will update this blog regularly .....
Let's not talk much about it. Just pick it up.
// Add a # Before the macro parameter. The macro parameter is automatically converted to a C 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 NSHomeD Irectory () # 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 stringwithuf8string :__ FILE _] lastPathComponent], _ LIN E __, [NSString stringWithFormat :( s), ##__ VA_ARGS _]) # else # define MRLog (s ,...) # endif // *** obtain the current year, month, day, hour, and second ************************* **************************************** * ********** # 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] // ** Converts an angle to a radian ******************************* **************************************** * ****************** # 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] appli CationFrame]. size. height # define App_Frame_Width [[UIScreen mainScreen] applicationFrame]. size. width // MainScreen Height & Width # define Main_Screen_Height [[UIScreen mainScreen] bounds]. size. height # define Main_Screen_Width [[UIScreen mainScreen] bounds]. size. width // View coordinates (x, y) and width and height (width, height) # define ViewxPos (v ). frame. origin. x # define ViewyPos (v ). frame. origin. y # define ViewWidth (v ). frame. Size. width # define ViewHeight (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) // default height of the system control # define kStatusBarHeight (20.f) # define kTopBarHeight (44.f) # define KBottomBarHeight (49.f) # define kCellDefaultHeight (44.f) # define kEnglishKeyboardHeight (216.f) # define trim (252.f )/********************* **************************************** **************************************** * **************/# pragma mark-Funtion Method (macro Method) // png jpg image path # define GetImagePathFromBundle (NAME) [[NSBundle mainBundle] pathForResource: [NSString stringWith UTF8String: 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_unio Rm (256)/255.0 green: arc4random_uniform (256)/255.0 blue: arc4random_uniform (256)/255.0 alpha: 1] // View rounded corner 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] flo AtValue]) # define DSystemVersion ([[[UIDevice currentDevice] systemVersion] doubleValue]) # define SSystemVersion ([[UIDevice currentDevice] systemVersion]) // current language # define CURRENTLANGUAGE ([[NSLocale preferredLanguages] objectAtIndex: 0]) // whether to Retina screen # define isRetina ([UIScreen instancesRespondToSelector: @ selector (currentMode)]? \ CGSizeEqualToSize (CGSizeMake (640,960), \ [UIScreen mainScreen] currentMode]. size): \ NO) // is it iPhone5 # define isiPhone5 ([UIScreen instancesRespondToSelector: @ selector (currentMode)]? \ CGSizeEqualToSize (CGSizeMake (640,113 6), \ [UIScreen mainScreen] currentMode]. size): \ NO) // iPad # define isPad (UI_USER_INTERFACE_IDIOM () = UIUserInterfaceIdiomPad) // UIView-viewWithTag # define VIEWWITHTAG (_ OBJECT, _ TAG) [_ OBJECT viewWithTag: _ TAG] // localized string/** what NSLocalizedString macro does is to find the resource file name "Localizable. strings "(parameter: Key + comment) */# define LocalString (x ,...) NSLocalizedString (x, nil)/** the NSLocalizedStringFromTable macro is used to find the resource file name "xxx. strings "(parameter: Key + file name + comment) */# define AppLocalString (x ,...) NSLocalizedStringFromTable (x, @ "someName", nil)
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.