关闭

iOS_常用宏定义汇总

119人阅读 评论(0) 收藏 举报

#pragma mark ===============常用的宏定义================

#define kScreenHeight [[UIScreen mainScreen] bounds].size.height

#define kScreenWidth [[UIScreen mainScreen] bounds].size.width

#define kStateBarHeight 20

#define kMainHeight (ScreenHeight - StateBarHeight)

#define kMainWidth ScreenWidth

//是否为retina

#define isRetina ([UIScreen instancesRespondToSelector:

@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), 

[[UIScreen mainScreen] currentMode].size) : NO)

//是否为7.0系统

#define IsIOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >=7.0 ? YES : NO)

//RGB色值

#define BACKGROUND_CORLOR  [UIColor colorWithRed:222.0/255 green:222.0/255 blue:222.0/255 alpha:1]

//16进制色值

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

//保存本地

#define kUserDefault [NSUserDefaults standardUserDefaults]

#define kApplication [UIApplication sharedApplication]

#define kDataEnv [DataEnvironment sharedDataEnvironment]

#define kDegreesToRadian(x) (M_PI * (x) / 180.0)

//弧度​

#define kRadianToDegrees(radian) (radian*180.0)/(M_PI)

//根据名称加载有缓存图片

#define kImageNamed(name) [UIImage imageNamed:name]

//判断系统的当前版本。

#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

#pragma mark ===============不常用的宏定义================

#define kSystemError @"系统繁忙,请稍后再试!"

//获取系统目录

#define kGetDirectory(NSSearchPathDirectory) [NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory, NSUserDomainMask, YES)lastObject]

//获取NSFILEMANAGER对象

#define kFileManager [NSFileManager defaultManager]

//获取程序代理 

#define kAppdelegate        ((AppDelegate *)[[UIApplication sharedApplication] delegate])

// 获取任意WINDOW对象 

#define kWindow             [[[UIApplication sharedApplication] windows] lastObject]

//获取KEYWINDOW对象

#define kKeyWindow          [[UIApplication sharedApplication] keyWindow]

//获取USERDEFAULTS对象

#define kNotificactionCenter [NSNotificationCenter defaultCenter]

// 获取当前控制器的navigationBar

#define kNavigationBar      [[self navigationController] navigationBar]

//简单提示框

#define kAlert(title, msg)  [[[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]show]

-----------------------------------加载图片-----------------------------------

//根据名称加载无缓存图片

#define kNoCacheImagewithName(name, ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:name ofType:ext]]

// 根据路径加载无缓存图片

#define kNoCacheImagewithPath(path) [UIImage imageWithContentsOfFile:path]

-----------------------------------视图-----------------------------------

// 根据TAG获取视图

#define kViewWithTag(PARENTVIEW, TAG, CLASS) ((CLASS *)[PARENTVIEW viewWithTag:TAG])

// 加载NIB文件 

#define kLOADNIBWITHNAME(CLASS, OWNER) [[[NSBundle mainBundle] loadNibNamed:CLASS owner:OWNER options:nil] lastObject]

// 异步 

#define kGCDAsync(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)

// 同步 

#define kGCDMain(block) dispatch_async(dispatch_get_main_queue(),block)

-----------------------------------界面尺寸--------------------------------------

 //导航栏高度 

#define kNavigationBarHeight 44

// 工具栏高度 

#define kTabBarHeight        49

// 是否IPad 

#define kIsIpad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

// 是否IPhone 

#define kIsIphone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

// 获取系统信息

#define kSystemVersion   [[UIDevice currentDevice] systemVersion]

// 获取当前语言环境 

#define kCurrentLanguage [[NSLocale preferredLanguages] objectAtIndex:0]

// 获取当前APP版本 

#define kAppVersion      [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]

//调试相关

#ifdef DEBUG

#define XLOG(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

#else

#define XLOG(...);

#endif


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:6375次
    • 积分:345
    • 等级:
    • 排名:千里之外
    • 原创:27篇
    • 转载:11篇
    • 译文:0篇
    • 评论:0条
    文章分类