iOS敏捷开发常见的宏定义

释放双眼,带上耳机,听听看~!
//--------------------获取设备大小-------------------

#define NavigationBar_HEIGHT44
#define SCREEN_WIDTH([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

//--------------------获取设备大小-------------------




//--------------------打印日志-------------------

//DEBUG模式下打印日志:当前行

#ifdef DEBUG
#define DLog(fmt,...) NSLog((@"%s [Line %d]" fmt),__PRETTY_FUNCTION__,__LINE__,##__VA_ARGS__)
#define NSLog(...) NSLog(__VA_ARGS__)
#else
#define DLog(...)
#define NSLog(...)
#endif




//重写NSLog,Debug模式下打印日志和当前行数

#if DEBUG
#define TLog(FORMAT,...) fprintf(stderr,"nfunction:%s line:%d content:%sn",__FUNCTION__,__LINE__,[[NSString stringWithFormat:FORMAT,##__VA_ARGS__] UTF8String])
#else
#define TLog(FORMAT,...)
#endif

//DEBUG 模式下打印日志,当前行并弹出一个警告

#ifdef DEBUG
#define ULog(fmt,...) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%sn [Line %d]",__PRETTY_FUNCTION__,__LINE__] message:[NSString stringWithFormat:fmt,##__VA_ARGS__] delegate:nil
cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];[alert show]; }
#else
#define ULog(...)
#endif





//一整套条件判断的日志打印

#define ITTDEBUG 1

#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(fmt,...) NSLog(@"%s(%d):" fmt,__PRETTY_FUNCTION__,__LINE__,##__VA_ARGS__)
#else
#define ITTDPRINT(fmt,...) ((void)0)
#endif

//Prints the current method's name

#define ITTDPRINTMETHODNAME() ITTDPRINT(@"%s",__PRETTY_FUNCTION__)

//Log-level based logging macros.

#if ITTLOGLEVEL_ERROR <= ITTMAXLOGLEVEL
#define ITTDERROR(fmt,...) ITTDPRINT(fmt,##__VA_ARGS__)
#else
#define ITTDERROR(fmt,...) ((void)0)


#endif




#if ITTLOGLEVEL_WARNING <= ITTMAXLOGLEVEL
#define ITTDWARNING(fmt,...) ITTDPRINT(fmt,##__VA_ARGS__)
#else
#define ITTDWARNING(fmt,...) ((void)0)
#endif

#if ITTLOGLEVEL_INFO <= ITTMAXLOGLEVEL
#define ITTDINFO(fmt,...) ITTDPRINT(fmt,##__VA_ARGS__)
#else
#define ITTDINFO(fmt,...) ((void)0)
#endif

//条件打印

#ifdef ITTDEBUG
#define ITTDCONDITIONLOG(condition,fmt,...) {
if(condition) {
ITTDPRINT(fmt,##__VA_ARGS__)
}
} ((void)0)
#else
#define ITTDCONDITIONLOG(condition,fmt,...) ((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)




//--------------------打印日志-------------------




//--------------------系统----------------------

//获取系统版本
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]
//获取当前系统的语言
#define CurrentLanguage [[NSLocale preferredLanguages] objectAtIndex:0]

//判断是否Retina屏、设备是否iPhone5、是否iPad

#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640,960),[[UIScreen mainScreen] currentModel].size) : NO)

#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentModel)] ? CGSizeEqualToSize(CGSizeMake(640,1136),[[UIScreen mainScreen] currentModel].size) : NO)

#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)





//判断是真机还是模拟器

#if TARGET_OS_IPHONE
//iPhone Device
#endif

#if TARGET_IPHONE_SIMULATOR
//iPhone Simulator
#endif





//检查系统版本

#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)//系统版本是否高于v版本
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)//系统版本是否高于或等于v版本
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)//系统版本是否低于v版本
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)//系统版本是否低于或等于v版本

//--------------------系统----------------------

//--------------------内存----------------------

//使用ARC和不使用ARC
#if __has_feature(objc_arc)
//compiling with ARC
#else
//compiling withOut ARC


#endif




//MRC情况下适用
#define RELEASE_SAFELY(__POINTER) {[__POINTER release];__POINTER = nil;}
#define SAFE_DELETE(p) if(p){[p release], p = nil;}
#define SAFE_RELEASE(xx) [xx release]; xx =nil

//--------------------内存----------------------




//--------------------图片----------------------

//读取本地图片
#define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:file ofType:ext]]
//定义UIImage对象
#define IMAGE(A) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:A ofType:nil]]
#define ImageNamed(__pointer) [UIImage imageNamed:[UIUtil imageName:__pointer]]

//note:前两者性能高于后者

//--------------------图片----------------------




//--------------------颜色类----------------------

//RGB颜色转换(16进制-> 10进制)

#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue &0xFF0000) >> 16))/255.0 green:((float)((rgbValue &0xFF00) >> 8))/255.0 blue:((float)(rgbValue &0xFF))/255.0 alpha:1.0]
//带有RGBA的颜色设置
#define COLOR(R,G,B,A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]

//--------------------颜色类----------------------




//--------------------其他类----------------------

//方正黑体简体字定义
#define FONT(F) [UIFont fontWithName:@"FZHTJW--GB1-0" size:F]

//设置View的tag属性
#define VIEWWITHTAG(_OBJECT, _TAG) [_OBJECT viewWithTag: _TAG]

//程序的本地化,引用国际化的文件
#define MyLocal(fmt,...) NSLocalizedString(fmt,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 实例化
#define USER_DEFAULT [NSUserDefaults standardUserDefaults]

//角度<===>弧度
#define degreesToRadian(degrees) (M_PI * (degrees) / 180.0) //获取弧度
#define radianToDegrees(redian) (((redian) * 180.0)/ M_PI) //获取角度

//单例化一个类

//定义
#define DEF_SINGLETON_FOR_CLASS(classname)
+(classname *)shared##classname;
//实现
#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:(struct _NSZone *)zone
{
@synchronized(self)
{
if (shared##classname == nil) {
shared##classname = [super allocWithZone:zone];
return shared##classname;
}
}
return nil;
}

-(id)copyWithZone:(struct _NSZone *)zone
{
return self;


}

 

人已赞赏
iOS文章

iOS开发:关于armv6、armv7、armv7s的区别

2020-5-19 23:48:02

iOS文章

iOS开发:UIScrollView如何禁止上下滑动

2020-5-20 1:03:02

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索