iOS常用宏定义

作者: Job_Yang | 来源:发表于2015-12-02 10:16 被阅读922次

尺寸相关

//状态栏高度
#define STATUS_BAR_HEIGHT 20
//NavBar高度
#define NAVIGATION_BAR_HEIGHT 44
//状态栏 + 导航栏 高度
#define STATUS_AND_NAVIGATION_HEIGHT  ((STATUS_BAR_HEIGHT) + (NAVIGATION_BAR_HEIGHT))

//屏幕 rect
#define SCREEN_RECT ([UIScreen mainScreen].bounds)
//屏幕宽度
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
//屏幕高度
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
#define CONTENT_HEIGHT (SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT - STATUS_BAR_HEIGHT)
//屏幕分辨率
#define SCREEN_RESOLUTION (SCREEN_WIDTH * SCREEN_HEIGHT * ([UIScreen mainScreen].scale))

//广告栏高度
#define BANNER_HEIGHT 215
#define STYLEPAGE_HEIGHT 21
#define SMALLTV_HEIGHT 77
#define SMALLTV_WIDTH 110
#define FOLLOW_HEIGHT 220
#define SUBCHANNEL_HEIGHT 62

系统相关

//获取系统版本         
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue] 
#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion] 

//获取系统时间戳
#define getCurentTime [NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]]

//判断是真机还是模拟器
#if TARGET_OS_IPHONE
//真机
#endif
#if TARGET_IPHONE_SIMULATOR
//模拟器
#endif

//获取当前语言  
#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0]) 

颜色图片相关

//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]  

//获取RGB颜色  
#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 LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]  

//定义UIImage对象  
#define IMAGE(A) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:A ofType:nil]]  

字符串相关

//字符串:
#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

沙盒路径相关

//文件目录
#define kPathTemp           NSTemporaryDirectory()
#define kPathDocument       [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
#define kPathCache          [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]
#define kPathSearch         [kPathDocument  stringByAppendingPathComponent:@"Search.plist"]
#define kPathMagazine       [kPathDocument stringByAppendingPathComponent:@"Magazine"]
#define kPathDownloadedMgzs [kPathMagazine stringByAppendingPathComponent:@"DownloadedMgz.plist"]
#define kPathDownloadURLs   [kPathMagazine stringByAppendingPathComponent:@"DownloadURLs.plist"]
#define kPathOperation      [kPathMagazine stringByAppendingPathComponent:@"Operation.plist"]
#define kPathSplashScreen   [kPathCache stringByAppendingPathComponent:@"splashScreen"]
#endif

其他

//DEBUG模式下打印日志,当前行  
#ifdef  DEBUG  
#define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);  
#else  
#define DLog(...)  
#endif 

//主要单例
#define UserDefaults [NSUserDefaults standardUserDefaults]
#define NotificationCenter [NSNotificationCenter defaultCenter]
#define SharedApplication [UIApplication sharedApplication]
#define Bundle [NSBundle mainBundle]#define MainScreen [UIScreen mainScreen]

//角度转弧度
#define DEGREES_TO_RADIANS(d) (d * M_PI / 180)

相关文章

  • iOS常用宏定义

    打印日志的几种写法 推荐文章iOS 日常工作之常用宏定义大全iOS常用宏定义 结束语 到这里就结束了,如若不懂的话...

  • iOS-常用宏定义

    [转自:iOS常用宏定义][http://www.cocoachina.com/ios/20161207/1831...

  • iOS 常用宏定义

    iOS 开发中使用一些常用宏定义可以大大提高开发效率,提高代码的重用性.以下是一些常用的宏定义: 像这些宏定义,在...

  • IOS NSLog宏定义

    IOS NSLog宏定义 标签(空格分隔): IOS IOS NSLog宏定义 宏定义NSLog方法,不用加";"...

  • iOS常用宏定义

    1.UI元素 //NavBar高度#defineNAVIGATIONBAR_HEIGHT 44//StatusBa...

  • iOS常用宏定义

    字符串是否为空 #define kStringIsEmpty(str) ([str isKindOfClass:[...

  • iOS常用宏定义

    字符串是否为空 数组是否为空 字典是否为空 是否是空对象 获取屏幕宽度与高度 ( " \ ":连接行标志,连接上下...

  • iOS常用宏定义

  • iOS常用宏定义

    #ifndef MacroDefinition_h #define MacroDefinition_h //---...

  • iOS常用宏定义

    整理 //常用宏定义 //是否为V以上系统 #define IOS(V) [[[UIDevice currentD...

网友评论

    本文标题:iOS常用宏定义

    本文链接:https://www.haomeiwen.com/subject/tcwhhttx.html