Macro definitions for IOS M.F.B. s

Source: Internet
Author: User

http://my.oschina.net/yongbin45/blog/150149

String:
#ifndef Niltoempty
#define Niltoempty (object) (Object!=nil)? object:@ ""
#endif

#ifndef Formatstringofobject
#define Formatstringofobject (object) [NSString stringwithformat:@ "%@", Object]
#endif

#ifndef Niltoemptyformatstringofobject
#define Niltoemptyformatstringofobject (object) Formatstringofobject (Niltoempty (object))
#endif



Image:
#ifndef ImagePath
#define IMAGEPATH (ImageName) [[NSBundle Mainbundle] pathforresource:imagename oftype:@ "PNG"]
#endif


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)
#define HEXCOLOR (c) [Uicolor colorwithred: ((c>>16) &0xff)/255.0f Green: ((c>>8) &0xff)/255.0f Blue :(c&0xff)/255.0f alpha:1.0f];


Debug
#define DEBUG (...) NSLog (@ "%s%@", __pretty_function__, [NSString stringwithformat:__va_args__])


IOS Support
#define Support_iphone_os_version (Version) (__iphone_os_version_min_required <= version && __iphone_os_ version_max_allowed >= Version)


Application delegate
#define APPLICATIONDELEGATE ((appdelegate *) [[uiapplication Sharedapplication] delegate])


Main single cases
#define USERDEFAULTS [Nsuserdefaults Standarduserdefaults]
#define Notificationcenter [Nsnotificationcenter Defaultcenter]
#define Sharedapplication [UIApplication sharedapplication]


#define Bundle [NSBundle Mainbundle]

#define Mainscreen [UIScreen Mainscreen]


Network instructions
#define Shownetworkactivityindicator () [UIApplication sharedapplication].networkactivityindicatorvisible = YES
#define Hidenetworkactivityindicator () [UIApplication sharedapplication].networkactivityindicatorvisible = NO
#define NETWORKACTIVITYINDICATORVISIBLE (x) [UIApplication sharedapplication].networkactivityindicatorvisible = x


Main control
#define NAVBAR Self.navigationController.navigationBar
#define TABBAR Self.tabBarController.tabBar


Size size
#define SCREENWIDTH [[UIScreen Mainscreen] Bounds].size.width
#define ScreenHeight [[UIScreen Mainscreen] Bounds].size.height

#define Navbarheight Self.navigationController.navigationBar.bounds.size.height
#define Tabbarheight Self.tabBarController.tabBar.bounds.size.height


#define Touchheightdefault 44.0f
#define Touchheightsmall 32.0f


#define Viewwidth (v) v.frame.size.width
#define Viewheight (v) v.frame.size.height
#define VIEWX (v) v.frame.origin.x
#define Viewy (v) v.frame.origin.y


#define Selfviewwidth Self.view.bounds.size.width
#define Selfviewheight Self.view.bounds.size.height


#define RECTX (Rect) rect.origin.x
#define RECTY (Rect) rect.origin.y
#define RECTWIDTH (Rect) rect.size.width
#define Rectheight (Rect) rect.size.height


#define RECTSETWIDTH (Rect, W) cgrectmake (Rectx (rect), recty (Rect), W, Rectheight (rect))
#define Rectsetheight (Rect, h) CGRectMake (Rectx (rect), recty (rect), Rectwidth (rect), h)
#define RECTSETX (rect, x) CGRectMake (x, Recty (rect), Rectwidth (rect), Rectheight (rect))
#define Rectsety (rect, y) CGRectMake (Rectx (rect), Y, Rectwidth (rect), Rectheight (rect))


#define RECTSETSIZE (Rect, W, h) CGRectMake (Rectx (rect), recty (Rect), W, h)
#define Rectsetorigin (rect, x, y) cgrectmake (x, Y, Rectwidth (rect), Rectheight (rect))



Memory management
#if! __has_feature (OBJC_ARC)
#define SBAUTORELEASE (__v) ([__v autorelease]);
#define Sbreturnautoreleased Sbautorelease

#define Sbretain (__v) ([__v retain]);
#define Sbreturnretained Sbretain

#define SBRELEASE (__v) ([__v release]);

#define SBDISPATCHQUEUERELEASE (__v) (Dispatch_release (__v));
#else
-fobjc-arc
#define SBAUTORELEASE (__V)
#define SBRETURNAUTORELEASED (__v) (__V)

#define Sbretain (__V)
#define SBRETURNRETAINED (__v) (__V)

#define SBRELEASE (__V)

#if Target_os_iphone
Compiling for IOS
#if __iphone_os_version_min_required >= 60000
IOS 6.0 or later
#define SBDISPATCHQUEUERELEASE (__V)
#else
IOS 5.X or earlier
#define SBDISPATCHQUEUERELEASE (__v) (Dispatch_release (__v));
#endif
#else
Compiling for Mac OS X
#if mac_os_x_version_min_required >= 1080
Mac OS X 10.8 or later
#define SBDISPATCHQUEUERELEASE (__V)
#else
Mac OS X 10.7 or earlier
#define SBDISPATCHQUEUERELEASE (__v) (Dispatch_release (__v));
#endif
#endif
#endif

Macro definitions for IOS M.F.B. s

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.