123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
#ifndef MacroDefinition_h #define MacroDefinition_h //AppDelegate #define APPDELEGATE [(AppDelegate*)[UIApplication sharedApplication] delegate] // ---------------------- System equipment ---------------------------- // Obtain the device screen size #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width) # Define SCREEN_HEIGHT ([UIScreen mainScreen]. bounds. size. height) // apply the size #define APP_WIDTH [[UIScreen mainScreen]applicationFrame].size.width #define APP_HEIGHT [[UIScreen mainScreen]applicationFrame].size.height // Obtain the system version #define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue] #define CurrentSystemVersion [[UIDevice currentDevice] systemVersion] #define isIOS4 ([[[UIDevice currentDevice] systemVersion] intValue]==4) #define isIOS5 ([[[UIDevice currentDevice] systemVersion] intValue]==5) #define isIOS6 ([[[UIDevice currentDevice] systemVersion] intValue]==6) #define isAfterIOS4 ([[[UIDevice currentDevice] systemVersion] intValue]>4) #define isAfterIOS5 ([[[UIDevice currentDevice] systemVersion] intValue]>5) #define isAfterIOS6 ([[[UIDevice currentDevice] systemVersion] intValue]>6) // Obtain the current language #define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0]) // Determine whether the Retina screen, device % fhone 5, or iPad is used #define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO) #define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO) #define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) // Determine whether it is a real machine or a simulator #if TARGET_OS_IPHONE //iPhone Device #endif #if TARGET_IPHONE_SIMULATOR //iPhone Simulator #endif // ---------------------- System equipment ---------------------------- // ---------------------- Memory-related ---------------------------- // Use and do not use ARC #if __has_feature(objc_arc) //compiling with ARC #else // compiling without ARC #endif // Release an object #define SAFE_DELETE(P) if(P) { [P release], P = nil; } #define SAFE_RELEASE(x) [x release];x=nil // ---------------------- Memory-related ---------------------------- // ---------------------- Image-related ---------------------------- // Read the local image #define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]] // Define the UIImage object #define IMAGE(A) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:A ofType:nil]] // Define the UIImage object #define ImageNamed(_pointer) [UIImage imageNamed:_pointer] // Tensile Image #define ResizableImage(name,top,left,bottom,right) [[UIImage imageNamed:name] resizableImageWithCapInsets:UIEdgeInsetsMake(top,left,bottom,right)] #define ResizableImageWithMode(name,top,left,bottom,right,mode) [[UIImage imageNamed:name] resizableImageWithCapInsets:UIEdgeInsetsMake(top,left,bottom,right) resizingMode:mode] // We recommend that you use the first two macro definitions with higher performance than the latter. // ---------------------- Image-related ---------------------------- // ---------------------- Color-related --------------------------- // Rgb color conversion (hexadecimal-> hexadecimal) #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] // Obtain the 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) // Background color #define BACKGROUND_COLOR [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0] // Clear the background color #define CLEARCOLOR [UIColor clearColor] // ---------------------- Color-related -------------------------- // ---------------------- Others ---------------------------- // Simplified font definition of 正 #define FONT(F) [UIFont fontWithName:@"FZHTJW--GB1-0" size:F] //file // Read the text content of the file, which is encoded as a UTF-8 by default #define FileString(name,ext) [[NSString alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(name) ofType:(ext)] encoding:NSUTF8StringEncoding error:nil] #define FileDictionary(name,ext) [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(name) ofType:(ext)]] #define FileArray(name,ext) [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(name) ofType:(ext)]] //G-C-D #define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block) #define MAIN(block) dispatch_async(dispatch_get_main_queue(),block) //Alert #define ALERT(msg) [[[UIAlertView alloc] initWithTitle:nil message:msg delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil] show] // Obtain the radians and radians from the angle to obtain the angle. #define degreesToRadian(x) (M_PI * (x) / 180.0) #define radianToDegrees(radian) (radian*180.0)/(M_PI) // ---------------------- Others ------------------------------- // ---------------------- View-related ---------------------------- // Set the text or image to be pasted #define PasteString(string) [[UIPasteboard generalPasteboard] setString:string]; #define PasteImage(image) [[UIPasteboard generalPasteboard] setImage:image]; // Obtain the X and Y coordinate points of the left top of the view. #define VIEW_TX(view) (view.frame.origin.x) #define VIEW_TY(view) (view.frame.origin.y) // Obtain the X and Y coordinate points of the right bottom of the view. #define VIEW_BX(view) (view.frame.origin.x + view.frame.size.width) #define VIEW_BY(view) (view.frame.origin.y + view.frame.size.height ) // Obtain the View Size: width and height. #define VIEW_W(view) (view.frame.size.width) #define VIEW_H(view) (view.frame.size.height) // Obtain the coordinate points X and Y of the frame. #define FRAME_TX(frame) (frame.origin.x) #define FRAME_TY(frame) (frame.origin.y) // Obtain the width and height of the frame. #define FRAME_W(frame) (frame.size.width) #define FRAME_H(frame) (frame.size.height) // ---------------------- View-related ---------------------------- // --------------------- Print the log -------------------------- // Print the log in Debug mode. The current row and function name #if DEBUG #define DLog(FORMAT, ...) fprintf(stderr,"\nfunction:%s line:%d content:%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]); #else #define NSLog(FORMAT, ...) nil #endif // Print logs in Debug mode. The current row and function name are displayed with a warning. #ifdef DEBUG # define WDLog(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]; } #else # define NSLog(...) #endif // Print the Frame #define LogFrame(frame) NSLog(@"frame[X=%.1f,Y=%.1f,W=%.1f,H=%.1f",frame.origin.x,frame.origin.y,frame.size.width,frame.size.height) // Print the Point #define LogPoint(point) NSLog(@"Point[X=%.1f,Y=%.1f]",point.x,point.y) // --------------------- Print the log -------------------------- #endif |