Macro on the tall define # define

Source: Internet
Author: User

Macro definition in many languages can see its shadow, C #, C++,c, and so on, especially the system API inside a lot of macro definition, looking very bluffing people. Reasonable use of macro definition, you can make your code look more standardized, more convenient, especially in certain places. Using a macro definition can also make your own code look tall with wood on it!

This article was changed from

On-line macro definition of iOS more, I summed up some of the most commonly used macros, follow up will continue to fill up.

1. First start judgment:

#define First_launched @"Firstlaunch"

2.IOS7 System judgment:

#define ISIOS7 ([[[Uidevice Currentdevice] systemversion] floatvalue] >=7.0? Yes:no)

3. Determine if the retina screen, whether IPhone5, whether the ipad

#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)

4. Load Picture macro:

#define LoadImage (File,type) [UIImage imagewithcontentsoffile:[[nsbundle mainbundle]pathforresource:file OfType: Type]]

5.rgb Color conversion (16 binary->10)

#define UICOLORFROMRGB (rgbvalue) [Uicolor colorwithred: ((float) ((Rgbvalue & 0xFF0000) >>))/255.0 Green: (( float) ((Rgbvalue & 0xff00) >> 8)/255.0 Blue: ((float) (Rgbvalue & 0xFF))/255.0 alpha:1.0]

6. Set color RGB

#define COLOR (R, G, B, A)

[Uicolor colorwithred:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]

7. Remove "-(ID) Performselector: (SEL) Aselector withobject: (ID) object;" The warning


do {\

_pragma ("clang diagnostic push") \

_pragma ("clang diagnostic ignored \"-warc-performselector-leaks\ "") \

Stuff; \

_pragma ("clang diagnostic pop") \

} while (0)

8. Conversion of angle and radians during circular motion.

9.获取屏幕 宽度、高度

#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width) #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height) //----------------------系统---------------------------- // 是否iPad #define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) // 是否iPad #define someThing (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)? ipad: iphone //获取系统版本 #define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue] #define CurrentSystemVersion [[UIDevice currentDevice] systemVersion] //获取当前语言 #define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0]) //判断是否 Retina屏、设备是否%fhone 5、是否是iPad #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) //判断设备的操做系统是不是ios7 #define IOS7 ([[[UIDevice currentDevice].systemVersion doubleValue] >= 7.0] //判断当前设备是不是iphone5 #define kScreenIphone5    (([[UIScreen mainScreen] bounds].size.height)>=568) //获取当前屏幕的高度 #define kMainScreenHeight ([UIScreen mainScreen].applicationFrame.size.height) //获取当前屏幕的宽度 #define kMainScreenWidth  ([UIScreen mainScreen].applicationFrame.size.width) //定义一个define函数 #define TT_RELEASE_CF_SAFELY(__REF) { if (nil != (__REF)) { CFRelease(__REF); __REF = nil; } } //判断是真机还是模拟器 #if TARGET_OS_IPHONE //iPhone Device #endif #if TARGET_IPHONE_SIMULATOR //iPhone Simulator #endif //检查系统版本 #define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame) #define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == 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:NSNumericSearch] == NSOrderedAscending) #define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

Macro on the tall define # define

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: 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.