iOS 开发 常用宏、方法整理

/设备系统相关

#define mIsPad    (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)  //是否ipad

#define mIsiphone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) //是否iPhone

#define mSystemVersion  ([[UIDevice currentDevice] systemVersion])  //系统版本

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

#define APPBOUNDLEID [[NSBundle mainBundle] bundleIdentifier] //bundleIdentifier

#define APPNAME [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]  //应用名称

#define APPVERSION [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] //版本号

/*判断设备是否是IPHONE5的屏幕*/

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

/*判断系统是否是IOS7*/

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

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

#define isIOS5 ([[[UIDevice currentDevice] systemVersion] floatValue] < 6.0 ? YES:NO)

//颜色转换

#define mRGBColor(r, g, b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0]

#define mRGBAColor(r, g, b, a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]

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

#define mRGBToColor(rgb) [UIColor colorWithRed:((float)((rgb & 0xFF0000) >> 16))/255.0 green:((float)((rgb & 0xFF00) >> 8))/255.0 blue:((float)(rgb & 0xFF))/255.0 alpha:1.0]

#define mScreenWidth          ([UIScreen mainScreen].bounds.size.width)//屏幕宽度

#define mScreenHeight        ([UIScreen mainScreen].bounds.size.height)//屏幕高度

#define mSCREEN_RATION  mScreenWidth/375.0

//顶部系统栏高度

#define kTopStatusBarHeight 20

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

#define mUserdefaults [NSUserDefaults standardUserDefaults]

#define kUDDeviceToken @"kUDDeviceToken"  //设备token

你可能感兴趣的:(iOS 开发 常用宏、方法整理)