Constant definition for IOS quick development

Source: Internet
Author: User
Tags constant definition home screen

Constant definition for IOS quick development
In IOS development, there are some methods that often need to be used, but there is a long method name, which leads to long code and tired of writing, we can solve these problems through macro definition. For example, we will encounter such a problem during code layout. We need to obtain the preceding Y axis coordinate, there are two ways to calculate xx by adding coordinates and height. frame. origin. y + xx. frame. size. height also has a slightly simpler method CGRectGetMaxY (xx. frame) is quite troublesome. At this time, we need to sacrifice macro definitions to help # define MaxY (v) CGRectGetMaxY (v ). frame) // you can use this definition to add the height of the control. The next time we get the Y coordinate, we just need to write MaxY (xx) gently. Is it much easier? Similarly, the image loading method # define IMAGENAMED (NAME) [UIImage imageNamed: NAME] is very convenient, the following is a sorted class # ifndef Medical_Wisdom_UConstants_h # define Medical_Wisdom_UConstants_h /************************** **************************** // ****** debug log **// /NSLog output information # ifdef DEBUG # define DLog (s ,...) NSLog (@ "<% @: (% d) >%@", [[NSString stringwithuf8string :__ FILE _] lastPathComponent], _ LINE __, [NSString stringWithFo Rmat :( s), ##__ VA_ARGS _]) # else # define DLog (s ,...) # endif/*** debug release */# if DEBUG # define MCRelease (x) # else # define MCRelease (x) # endif/****** release ******/# define NILRelease [x release], x = nil # pragma mark-Frame (macro x, y, width, height) # define MainScreenScale [[UIScreen mainScreen] scale] // when the screen resolution is 1, a normal screen is displayed and 2 is displayed, display the Retian screen // App Frame Height & Width # define Application_Frame [[UIScreen mainScreen] applicationFrame] // remove the frame of the screen in the signal area # define APP_Frame_Height [[UIScreen mainScreen] applicationFrame]. size. height // The screen height of the application # define App_Frame_Width [[UIScreen mainScreen] applicationFrame]. size. width // application screen Width/*** MainScreen Height width */# define Main_Screen_Width [[UIScreen mainScreen] bounds]. size. width // The width of the home screen # define Main_Screen_Height [[UIScreen mainScreen] bounds]. si Ze. height // height of the home screen # define Main_Screen_Height_without_top [[UIScreen mainScreen] bounds]. size. height-64 // height of the home screen // View coordinates (x, y) and width (width, height) # define X (v ). frame. origin. x # define Y (v ). frame. origin. y # define WIDTH (v ). frame. size. width # define HEIGHT (v ). frame. size. height # define MinX (v) CGRectGetMinX (v ). frame) // obtain the x coordinate of the control screen # define MinY (v) CGRectGetMinY (v ). frame) // obtain the Y coordinate of the control screen # define MidX (v) CGRectGetMidX (v ). frame) // Add the abscissa to the midpoint coordinate of the control # define MidY (v) CGRectGetMidY (v ). frame) // Add the ordinate to the control's midpoint coordinate # define MaxX (v) CGRectGetMaxX (v ). frame) // the x-axis plus the control width # define MaxY (v) CGRectGetMaxY (v ). frame) // Add the height of the control to the ordinate # define CONTRLOS_FRAME (x, y, width, height) CGRectMake (x, y, width, height) // default height of the system control # define kStatusBarHeight (effecf) # define kTopBarHeight (44.f) # define kBottomBarHeight (49.f) # define kCellDefa UltHeight (44.f) # define KstatusBarAndNavigation (64.0) // left-side horizontal when the control is full screen # define kFrameX (0.0) # define kFrameY (0.0) # define kPhoneWithStatusNoPhone5Height (480.0) # define increment (460.0) # define kPhoneWithStatusPhone5Height (568.0) # define increment (548.0) # define kPadFrameWidth (768.0) # define kPadWithStatusHeight (1024.0) # define kPadNoWithStatusHeight (100) 4.0) // The height of the keyboard in both Chinese and English States # define kEnglishKeyboardHeight (216.f) # define kChineseKeyboardHeight (252.f) # pragma mark-Funtion Method (macro Method) // png jpg image path # define PNGPATH (NAME) [[NSBundle mainBundle] pathForResource: [NSString stringwithuf8string: NAME] ofType: @ "png"] # define JPGPATH (NAME) [[NSBundle mainBundle] pathForResource: [NSString stringwithuf8string: NAME] ofType: @ "jpg"] # define PATH (NAME, EXT) [[NSBundl E mainBundle] pathForResource :( NAME) ofType :( EXT)] // load the image # define PNGIMAGE (NAME) [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource :( NAME) ofType: @ "png"] # define JPGIMAGE (NAME) [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource :( NAME) ofType: @ "jpg"] # define IMAGE (NAME, EXT) [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource :( NAME) ofType :( EXT)] # define IMAGENAMED (NAME) [UIImage imageNamed: NAME] // font size (regular/bold) # define BOLDSYSTEMFONT (FONTSIZE) [UIFont boldSystemFontOfSize: FONTSIZE] # define SYSTEMFONT (FONTSIZE) [UIFont systemFontOfSize: FONTSIZE] # define FONT (NAME, FONTSIZE) [UIFont fontWithName :( NAME) size :( FONTSIZE)] // color (RGB) # define RGBCOLOR (r, g, B) [UIColor colorWithRed :( r)/255.0f green :( g)/255.0f blue :( B)/255.0f alpha: 1] # define RGBACO LOR (r, g, B, a) [UIColor colorWithRed :( r)/255.0f green :( g)/255.0f blue :( B)/255.0f alpha :( a)] # define BACKGROUND_COLOR [UIColor colorWithRed: 22/255. 0f green: 29/255. 0f blue: 38/255. 0f alpha: 1] // current version # define FSystenVersion ([[[UIDevice currentDevice] systemVersion] floatValue]) # define DSystenVersion ([[[UIDevice currentDevice] systemVersion] doubleValue]) # define SSystemVersion ([[UIDevice currentDevice] s YstemVersion]) // 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) // iPhone5 # define ISIPHONE [[UIDevice currentDevice] userInterfaceIdiom] = UIUserInterfaceIdiomPhone # define ISIPHONE5 ([UIScreen instancesRespondToSelector: @ selector (currentMode)]? CGSizeEqualToSize (CGSizeMake (640,113 6), [[UIScreen mainScreen] currentMode]. size): NO) # define ISIPHONE6 ([UIScreen instancesRespondToSelector: @ selector (currentMode)]? CGSizeEqualToSize (CGSizeMake (750,133 4), [[UIScreen mainScreen] currentMode]. size): NO) # define ISIPHONE6P ([UIScreen instancesRespondToSelector: @ selector (currentMode)]? CGSizeEqualToSize (CGSizeMake (1242,220 8), [[UIScreen mainScreen] currentMode]. size): NO) // whether it is iPad # define isPad (UI_USER_INTERFACE_IDIOM () = UIUserInterfaceIdiomPad) # define YELLO_APP [UIColor colorWithRed: 255/255 green: 148.0/255 blue: 28.0/255 alpha: 1] // UIView-viewWithTag obtain the subview by tag value # define VIEWWITHTAG (_ OBJECT, _ TAG) [_ OBJECT viewWithTag: _ TAG] // Application name # define AppDisplayName [[NSBundle mainBundle] objectForInfoDictionaryKey: @ "CFBundleDisplayName"] // RGB color conversion (hexadecimal-> decimal) # define UIColorFromRGB (rgbValue) [UIColor colorWithRed :( (float) (rgbValue & 0xFF0000)> 16)/255.0 green :( (float) (rgbValue & 0xFF00)> 8)/255.0 blue :( (float) (rgbValue & 0xFF)/255.0 alpha: 1.0] // determine whether the Device room is a real machine or a Simulator # if TARGET_ OS _IPHONE/** iPhone Device */# endif # if TARGET_IPHONE_SIMULATOR/** iPhone Simulator */# endif this is under development it can slightly improve efficiency, OC syntax is a bit annoying. Learn swift now, ^ _ ^

Related Article

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.