Common macro definitions for IOS----------

Source: Internet
Author: User

In our daily projects, reasonable use of macro definitions, will greatly reduce the amount of our code, as well as the readability of the code, for the convenience of readers, summarized as follows:

pragma mark-application related
///=============================================================================@name Application///=============================================================================#Define application [UIApplication Sharedapplication]#Define Appdle (appdelegate*) [Application delegate]#Define Kkeywindow [UIApplication Sharedapplication].keywindow#define kuserdefaults [nsuserdefaults Standarduserdefaults]#define kNotificationCenter [ Nsnotificationcenter defaultcenter]//get Temp#define kpathtemp nstemporarydirectory () //get sandbox Document#define kpathdocument [Nssearchpathfordirectoriesindomains ( NSDocumentDirectory, Nsuserdomainmask, YES) firstobject]//get sandbox Cache #define Kpathcache [Nssearchpathfordirectoriesindomains ( Nscachesdirectory, Nsuserdomainmask, YES) firstobject]///============================= ================================================ 
pragma mark-frame related
///=============================================================================/// @name Frame相关///=============================================================================// 控件尺寸比例#define kScreenRate (kScreenWidth/375.f)// 实际尺寸#define kSuitSize(size) kScreenRate * (size)///=============================================================================
pragma mark-screen coordinates, size dependent
///=============================================================================@name screen coordinates, size-dependent///=============================================================================Determine if the iphone X#Define IS_IPHONEX ([UIScreen instancesrespondtoselector: @selector (currentmode)]? Cgsizeequaltosize (Cgsizemake (1125, 2436), [[UIScreen Mainscreen] currentmode].size): NO)Screen height#Define Kscreenheight [[UIScreen Mainscreen] Bounds].size.heightScreen width#Define Kscreenwidth [[UIScreen Mainscreen] Bounds].size.widthStatus bar Height#Define Kstatusbarheight (Is_iphonex? 44.F:20.F)//Top navigation bar height #define knavigationbarheight 44.f//Top safe Distance #define Ksafeareatopheight (Is_iphonex? 88.F:64.F)//Bottom safe Distance #define Ksafeareabottomheight (Is_iphonex? 34.F:0.F)//Tabbar height #define ktabbarheight 49.f//Remove upper navigation bar remaining middle view Height #define Contentheight ( Kscreenheight-ksafeareatopheight-ksafeareabottomheight-ktabbarheight)///================================= ============================================ 
pragma mark-system-related
///=============================================================================@name System-related///=============================================================================App version number#define device_app_version (NSString *) [[NSBundle Mainbundle] Objectforinfodictionarykey:@ "cfbundleshortversionstring"]//App build version number #define device_app_build ( NSString *) [[[NSBundle Mainbundle] infodictionary] objectforkey:@ "CFBundleVersion"] //system version number (string) #define device_os_version [[Uidevice Currentdevice] Systemversion]//system version number (float) #define device_os_version_value [device_os_version FloatValue]///=============================================================================  
pragma mark-font, color related
///=============================================================================@name font, color related///=============================================================================#Define Font_size (f) [Uifont systemfontofsize: (f)]#Define Font_bold_size (f) [Uifont boldsystemfontofsize: (f)]#Define Font_italic_size (f) [Uifont italicsystemfontofsize: (f)]#define RGBCOLOR (r,g,b) [Uicolor colorwithred: (r)/255.f Green: (g)/255.F Blue: (b)/255.f alpha:1.f]#define Rgbacolor (r,g,b,a) [Uicolor colorwithred: (r)/255.f Green: (g)/255.F Blue: (b)/255.f Alpha: (a)] #define randomcolor [Uicolor colorWithRed:arc4random_ Uniform (/255.0) green:arc4random_uniform (/255.0 blue:arc4random_uniform)/255.0 alpha:1.0]#define Colorwithhex (rgbvalue) [Uicolor colorwithred: ((float) (( Rgbvalue & 0xFF0000) >>)/255.0 Green: ((float) ((Rgbvalue & 0xff00) >> 8)/255.0 Blue: ((float) (R Gbvalue & 0xFF)/255.0 alpha:1.0]///============================================== ===============================
pragma mark-nslog related
///========================================= ====================================///@name nslog related ///== ===========================================================================#ifdef debug#define MLLog (...) NSLog (@ "%s line%d \ n%@\n\n", __func__,__line__,[nsstring stringwithformat:__va_args__ ]) #else# Define NSLOG (...) #endif///=================== ========================================================== 
pragma mark-Determine if the data is empty
///========================================= ====================================///@name determine if the data is empty ///= ============================================================================#define kstringisempty (str) ([str iskindofclass:[nsnull class]] | | str = = NIL | | [STR length] < 1? Yes:no) #define Karrayisempty (array) (array = = Nil | | [Array Iskindofclass:[nsnull class] | | Array.count = = 0) #define Kdictisempty (DIC) (dic = Nil | | [dic Iskindofclass:[nsnull class] | | Dic.allkeys = = 0) ///================================================================= ============




Common macro definitions for IOS----------

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.