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
#define SUPPRESSPERFORMSELECTORLEAKWARNING (Stuff) \
do {\
_pragma ("clang diagnostic push") \
_pragma ("clang diagnostic ignored \"-warc-performselector-leaks\ "") \
Stuff; \
_pragma ("clang diagnostic pop") \
} while (0)
===================================== IOS common macro definition fast ice-eating2015-03-04 11:20:13
#ifndef Macrodefinition_h
#define Macrodefinition_h
-------------------get the device size-------------------------
NavBar Height
#define Navigationbar_height 44
Get screen width, height
#define SCREEN_WIDTH ([UIScreen mainscreen].bounds.size.width)
#define Screen_height ([UIScreen mainscreen].bounds.size.height)
-------------------get the device size-------------------------
-------------------Print Log-------------------------
Print log in DEBUG mode, when moving forward
#ifdef DEBUG
# define DLOG (FMT, ...) NSLog (@ "%s [line%d]" FMT), __pretty_function__, __line__, # #__VA_ARGS__);
#else
# define DLOG (...)
#endif
To rewrite the print log and the current number of lines in Nslog,debug mode
#if DEBUG
#define NSLOG (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 log in DEBUG mode, current line and pop up a warning
#ifdef DEBUG
# define Ulog (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 Ulog (...)
#endif
#define Ittdebug
#define ITTLOGLEVEL_INFO 10
#define Ittloglevel_warning 3
#define ITTLOGLEVEL_ERROR 1
#ifndef Ittmaxloglevel
#ifdef DEBUG
#define Ittmaxloglevel Ittloglevel_info
#else
#define Ittmaxloglevel Ittloglevel_error
#endif
#endif
The general purpose logger. This ignores logging levels.
#ifdef Ittdebug
#define Ittdprint (XX, ...) NSLog (@ "%s (%d):" XX, __pretty_function__, __line__, # #__VA_ARGS__)
#else
#define Ittdprint (XX, ...) ((void) 0)
#endif
Print the name of the current method
#define ITTDPRINTMETHODNAME () Ittdprint (@ "%s", __pretty_function__)
Log-level based logging macros.
#if ittloglevel_error <= Ittmaxloglevel
#define ITTDERROR (XX, ...) Ittdprint (XX, # #__VA_ARGS__)
#else
#define ITTDERROR (XX, ...) ((void) 0)
#endif
#if ittloglevel_warning <= Ittmaxloglevel
#define Ittdwarning (XX, ...) Ittdprint (XX, # #__VA_ARGS__)
#else
#define Ittdwarning (XX, ...) ((void) 0)
#endif
#if ittloglevel_info <= Ittmaxloglevel
#define ITTDINFO (XX, ...) Ittdprint (XX, # #__VA_ARGS__)
#else
#define ITTDINFO (XX, ...) ((void) 0)
#endif
#ifdef Ittdebug
#define ITTDCONDITIONLOG (condition, XX, ...) {if ((condition)) {\
Ittdprint (XX, # #__VA_ARGS__); \
} \
} ((void) 0)
#else
#define ITTDCONDITIONLOG (condition, XX, ...) ((void) 0)
#endif
#define ITTASSERT (condition, ...) \
do {\
if (! ( condition)) {\
[Nsassertionhandler Currenthandler] \
Handlefailureinfunction:[nsstring stringwithutf8string:__pretty_function__] \
File:[nsstring stringwithutf8string:__file__] \
LINENUMBER:__LINE__ \
DESCRIPTION:__VA_ARGS__]; \
} \
} while (0)
---------------------Print Log--------------------------
----------------------System----------------------------
whether ipad
#define ISPAD (ui_user_interface_idiom () = = Uiuserinterfaceidiompad)
whether ipad
#define SomeThing (ui_user_interface_idiom () = = Uiuserinterfaceidiompad)? Ipad:iphone
Get System version
#define Ios_version [[Uidevice Currentdevice] systemversion] floatvalue]
#define Currentsystemversion [Uidevice Currentdevice] systemversion]
Get the current language
#define CURRENTLANGUAGE ([Nslocale preferredlanguages] objectatindex:0])
Determine if the retina screen, whether the device is%fhone 5, is an 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)
Judging the device's operating system is not iOS7
#define IOS7 ([[Uidevice currentdevice].systemversion Doublevalue] >= 7.0]
Determine if the current device is iphone5
#define KSCREENIPHONE5 (([UIScreen mainscreen] bounds].size.height) >=568)
Gets the height of the current screen
#define Kmainscreenheight ([UIScreen mainscreen].applicationframe.size.height)
Gets the width of the current screen
#define KMAINSCREENWIDTH ([UIScreen mainscreen].applicationframe.size.width)
Define a define function
#define Tt_release_cf_safely (__ref) {if (Nil! = (__ref)) {cfrelease (__ref); __ref = nil;}}
Judging whether it's a real machine or a simulator
#if Target_os_iphone
IPhone Device
#endif
#if Target_iphone_simulator
IPhone Simulator
#endif
Check the system version
#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)
----------------------System----------------------------
----------------------Memory----------------------------
Use arc and do not use arc
#if __has_feature (OBJC_ARC)
Compiling with ARC
#else
Compiling without ARC
#endif
#pragma mark-common functions
#define Release_safely (__pointer) {[__pointer RELEASE]; __pointer = nil;}
Releasing an Object
#define SAFE_DELETE (P) if (p) {[P release], p = nil;}
#define SAFE_RELEASE (x) [x Release];x=nil
----------------------Memory----------------------------
----------------------Pictures----------------------------
Reading local Pictures
#define LoadImage (File,ext) [UIImage imagewithcontentsoffile:[nsbundle mainbundle]pathforresource:file OfType:ext]
Defining UIImage Objects
#define IMAGE (A) [UIImage imagewithcontentsoffile:[nsbundle Mainbundle] pathforresource:a Oftype:nil]
Defining UIImage Objects
#define IMAGENAMED (_pointer) [UIImage imagenamed:[uiutil Imagename:_pointer]
The first two macro definitions are recommended, with higher performance than the latter
----------------------Pictures----------------------------
----------------------Color Class---------------------------
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]
Color settings with RGBA
#define COLOR (R, G, B, A) [Uicolor colorwithred:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
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)
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 background color
#define Clearcolor [Uicolor Clearcolor]
#pragma mark-color functions
#define RGBCOLOR (r,g,b) [Uicolor colorwithred: (r)/255.0f Green: (g)/255.0f Blue: (b)/255.0f Alpha:1]
#define RGBACOLOR (r,g,b,a) [Uicolor colorwithred: (r)/255.0f Green: (g)/255.0f Blue: (b)/255.0f Alpha: (a)]
----------------------Color Class--------------------------
----------------------Other----------------------------
Definition of founder's bold and simplified body
#define FONT (F) [Uifont fontwithname:@ "fzhtjw--gb1-0" size:f]
Define an API
#define APIURL @ "http://xxxxx/"
Login API
#define Apilogin [Apiurl stringbyappendingstring:@ "Login"]
Set the Tag property of the View
#define VIEWWITHTAG (_object, _tag) [_object viewwithtag: _tag]
Localization of programs, referencing internationalized files
#define MYLOCAL (x, ...) Nslocalizedstring (x, nil)
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)
Nsuserdefaults instantiation
#define User_default [Nsuserdefaults Standarduserdefaults]
Get radians from angle get angle
#define Degreestoradian (x) (M_PI * (x)/180.0)
#define Radiantodegrees (Radian) (radian*180.0)/(M_PI)
Singleton a class
#define SYNTHESIZE_SINGLETON_FOR_CLASS (classname) \
\
static classname *shared# #classname = nil; \
\
+ (classname *) shared# #classname \
{ \
@synchronized (self) \
{ \
if (shared# #classname = = nil) \
{ \
shared# #classname = [self alloc] init]; \
} \
} \
\
return shared# #classname; \
} \
\
+ (ID) Allocwithzone: (nszone *) zone \
{ \
@synchronized (self) \
{ \
if (shared# #classname = = nil) \
{ \
shared# #classname = [Super Allocwithzone:zone]; \
return shared# #classname; \
} \
} \
\
return nil; \
} \
\
-(ID) Copywithzone: (nszone *) zone \
{ \
return self; \
}
#endif
==========================
Use macro definitions to improve development efficiency in IOS development