iOS_常用宏定义汇总

#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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值