Macros for IOS M.F.B. s

Source: Internet
Author: User

Original address: 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//Picture: #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&AMP;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 example # define Userdefaults [Nsuserdefaults standarduserdefaults] #define Notificationcenter [Nsnotificationcenter Defaultcenter] #de Fine sharedapplication [uiapplication sharedapplication] #define Bundle [NSB Undle Mainbundle] #define Mainscreen [uiscreen mainscreen]//Network Indication # define Shownetworkactivityindic Ator () [UIApplication sharedapplication].networkactivityindicatorvisible = Yes#define HideNetworkActivityIndicator ( ) [UIApplication sharedapplication].networkactivityindicatorvisible = No#define networkactivityindicatorvisible (x) [ UIApplication sharedapplication].networkactivityindicatorvisible = x//Main control # define NavBar SE Lf.navigationController.naVigationbar#define TabBar self.tabbarcontroller.tabbar//Size Size # # ScreenWidth [[UIScreen Mainscreen] Bounds].size.width#define screenheight [[UIScreen Mainscreen] B Ounds].size.height#define Navbarheight self.navigationcontroller.navigationbar.bounds.size.height#d                  Efine 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.or Igin.x#define Viewy (v) v.frame.origin.y#define selfviewwidth Self.view.bo                            Unds.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.widt H#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), rect Height (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 SbreturnretainedSbretain #define SBRELEASE (__v) ([__v release]); #define SBDISPATCHQUEUERELEASE (__v) (Dispatch_release (__v)), #else//-fobjc-arc #define SBAUTORELEASE (__V) #defin E 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 >=//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

The most efficient and frequently used macros in iOS development (RPM)

Original address: http://blog.csdn.net/duxinfeng2010/article/details/9067947

Supplement 1//----------------------picture----------------------------    //read local picture  #define LoadImage (File,ext) [ UIImage imagewithcontentsoffile:[[nsbundle mainbundle]pathforresource:file Oftype:ext]]    //define UIImage Object  # Define IMAGE (A) [UIImage imagewithcontentsoffile:[[nsbundle Mainbundle] pathforresource:a Oftype:nil]    // Define UIImage Object  #define IMAGENAMED (_pointer) [UIImage imagenamed:[uiutil Imagename:_pointer]]    //recommend using the first two macro definitions, Performance is higher than the latter  //----------------------picture----------------------------  
Supplemental 2//----------------------Other----------------------------//Fangzheng Bold definition #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 Viewwithta G: _tag]//program localization, 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)//nsuserdefaults instantiation #define MAIN (block) Dispatch_async (Dispatch_get_main_queue (), block) #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 one 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) \ {\ sh ared# #classname = [Super Allocwithzone:zone]; \ return shared# #classname; \} \} \ \ return nil; \} \ \-(ID) Copywithzone: (nszone *) zone \ {\ return self; \} #endif
Supplemental 3//----------------------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 Colorwit hred: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_colo R [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 b Lue: (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--------------------------  
Supplemental 4//----------------------System----------------------------//Get System version #define IOS_VERSION [[[Uidevice Currentdevice] Systemversion] Floatvalue] #define Currentsystemversion [[Uidevice Currentdevice] systemversion]//Get current language #define Cur Rentlanguage ([[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 Insta Ncesrespondtoselector: @selector (currentmode)]? Cgsizeequaltosize (Cgsizemake (640, 1136), [[UIScreen Mainscreen] currentmode].size): NO) #define ISPAD (Ui_user_ Interface_idiom () = = Uiuserinterfaceidiompad)//Judging whether it is a real machine or an emulator #if target_os_iphone//iphone Device #endif #if Targ Et_iphone_simulator//iphone SIMULATOR #endif//Check the system version #define SYSTEM_VERSION_EQUAL_TO (v) ([[[Uidev Ice Currentdevice] systemversion] compare:v OptiOns:nsnumericsearch] = = nsorderedsame) #define System_version_greater_than (v) ([[[Uidevice Currentdevice] Sy Stemversion] compare:v Options:nsnumericsearch] = = nsordereddescending) #define System_version_greater_than_or_equal _to (v) ([[[Uidevice Currentdevice] systemversion] compare:v options:nsnumericsearch]! = nsorderedascending) #define SYS Tem_version_less_than (v) ([[[Uidevice Currentdevice] systemversion] compare:v options:nsnumericsearch] = = nsorderedascending) #define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO (v) ([[[[Uidevice Currentdevice] systemVersion] Compa  Re:v Options:nsnumericsearch]! = nsordereddescending)//----------------------system----------------------------

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.