欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

iOS开发常用的宏

程序员文章站 2022-05-18 10:14:46
#define screen_width ([uiscreen mainscreen].bounds.size.width) #define screen_height ([ui...

#define screen_width ([uiscreen mainscreen].bounds.size.width)
#define screen_height ([uiscreen mainscreen].bounds.size.height)
#define safe_release(x) [x release];x=nil
#define ios_version [[[uidevice currentdevice] systemversion] floatvalue]
#define currentsystemversion ([[uidevice currentdevice] systemversion]) 
#define currentlanguage ([[nslocale preferredlanguages] objectatindex:0])
 
#define background_color [uicolor colorwithred:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0]
 
 
//use dlog to print while in debug model
#ifdef debug
#   define dlog(fmt, ...) nslog((@"%s [line %d] " fmt), __pretty_function__, __line__, ##__va_args__);
#else
#   define dlog(...)
#endif
 
 
#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)
 
 
#if target_os_iphone
//iphone device
#endif
 
#if target_iphone_simulator
//iphone simulator
#endif
 
 
//arc
#if __has_feature(objc_arc)
    //compiling with arc
#else
    // compiling without arc
#endif
 
 
//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)
 
 
#define user_default [nsuserdefaults standarduserdefaults]
 
#pragma mark - degrees/radian functions
#define degreestoradian(x) (m_pi * (x) / 180.0)
#define radiantodegrees(radian) (radian*180.0)/(m_pi)
 
#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)]
 


#define   width   [[uiscreen mainscreen] bounds].size.width
#define  height  [[uiscreen mainscreen] bounds].size.height