iOS 常用宏定义

#ifdef DEBUG
#define DLog(format, ...) printf("class: <%p %s:(%d) > method: %s \n%s\n", self, [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat:(format), ##__VA_ARGS__] UTF8String] )
//#   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#   define DLog(...)
#endif

#define _weakself              __weak typeof(self)      weakself = self
#define WEAK_SELF              __weak typeof(self)      weakSelf = self;

// 颜色
#define UIColorFromHEXA(hex,a)      [UIColor colorWithRed:((hex & 0xFF0000) >> 16) / 255.0f green:((hex & 0xFF00) >> 8) / 255.0f blue:(hex & 0xFF) / 255.0f alpha:a]
#define UIColorFromRGBA(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:a]

// 设置RGB颜色
#define RGB(r,g,b)          [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define RGBS(r,g,b,s)       [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:s]
#define  RandomColor(a)     [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:(a)]


#define rgba(r,g,b,s)       [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:s]
#define hexa(hex,a)         [UIColor colorWithRed:((hex & 0xFF0000) >> 16) / 255.0f green:((hex & 0xFF00) >> 8) / 255.0f blue:(hex & 0xFF) / 255.0f alpha:a]

// 系统默认字体设置和自选字体设置
#define SystemFontSize(fontsize)            [UIFont systemFontOfSize:(fontsize)]
#define SystemBoldFontSize(fontsize)        [UIFont boldSystemFontOfSize:(fontsize)]
#define CustomFontSize(fontname,fontsize)   [UIFont fontWithName:fontname size:fontsize]

//获取图片资源
#define GetImage(imageName)    [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]
#define imageDomain(imageName) [NSString stringWithFormat:@"%@/upload/%@", REQUEST,imageName]


// 等比例缩放系数
#define KEY_WINDOW    ([UIApplication sharedApplication].keyWindow)
#define SCREEN_WIDTH  ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)

#define SCREEN_SCALE     ((SCREEN_WIDTH > 414) ? (SCREEN_HEIGHT/375.0) : (SCREEN_WIDTH/375.0))
#define Handle(x)        ((x)*SCREEN_SCALE)
#define Handle_width(w)  ((w)*SCREEN_SCALE)
#define Handle_height(h) ((h)*SCREEN_SCALE)

/*===================================
 屏幕宽高
 ===================================*/
#define AppWidth       [UIScreen mainScreen].bounds.size.width
#define AppHeight      [UIScreen mainScreen].bounds.size.height
#define AppBounds      [UIScreen mainScreen].bounds
#define WidthRatio     (AppWidth/375.0f)
#define HeightRatio    (AppHeight/667.0f)

// 字体
#define Font(s)        [UIFont systemFontOfSize:(s)*WidthRatio]

/*===================================
 状态,导航,TabBar
 ===================================*/
#define StatusH        [[UIApplication sharedApplication] statusBarFrame].size.height //状态高度
#define NavigaBarH     self.navigationController.navigationBar.frame.size.height
#define NavigaH        (StatusH + NavigaBarH) //整个导航栏高度
#define TabbarH        AppHeight > 811.0 ? 83.0 : 49.0 //TabBar高度
#define App(s,g)       (s)-(g)

// 网络状态
#define NetWork_MobileNet           @"MobileNet" //3G|4G
#define NetWork_WIFI                @"WIFI" //WIFI
#define NetWork_NONET               @"NONET" //NONET
#define NetworkChangeNotification   @"NetworkChangeNotification"

#pragma mark --------------------------protocal----------------------------
/**
 iPhoneX适配
 */
#define iPhone__X                   ([UIScreen instanceMethodForSelector:@selector(currentMode)]?CGSizeEqualToSize(CGSizeMake(1125,2436),[[UIScreen mainScreen] currentMode].size):NO)

#define kTABBAR_HEIGHT              (iPhoneX?(49.f+34.f):49.f)

/**
 Return the statusBar height.
 */
#define kSTATUSBAR_HEIGHT (iPhoneX?44.0f:20.f)

#define LiveRemandViewY   (iPhoneX?44.0f:0.f)

/**
 Return the navigationBar height.
 */
#define kNAVIGATION_HEIGHT (44.f)

/**
 Return the (navigationBar + statusBar) height.
 */
#define kSTATUSBAR_NAVIGATION_HEIGHT (iPhoneX?88.0f:64.f)

/**
 Return 没有tabar 距 底边高度
 */
#define BOTTOM_SPACE_HEIGHT (iPhoneX?34.0f:0.0f)
/**
 Return FLYVIEW 高度
 */
#define FLYVIEW_SPACE_HEIGHT (KIPHONEXPLUST?300.0f:260.0f)

// 通用控件左右间隔
#define kSpaceToLeftOrRight Handle(10)

// 底部条高度
#define kBottomViewHeight 48

// 导航条高度
#define  kNavigationHeight 64

#define ChatToolsHeight         50          // 聊天工具框高度
#define EmojiKeyboard_Height    200         // 表情键盘的高度
#define LiveChatToolsHeight     49          // 直播间聊天工具栏高度
#define Live_EmojiKeyboard_Height  200      // 直播间表情键盘高度


////////////////////////////////////////

#define APPLICATION         [UIApplication sharedApplication]
#define APPDLE              (AppDelegate*)[APPLICATION delegate]
// 将NSUserDefaults的实例化定义成宏
#define UserDedaults        [NSUserDefaults standardUserDefaults]
// 将NSUserDefaults同步数据
#define UserDedaultsSyn     [[NSUserDefaults standardUserDefaults] synchronize]
// 将NSNotificationCenter的实例化定义成宏
#define NotificationCenter  [NSNotificationCenter  defaultCenter]

// 屏幕宽度
//#define SCREEN_WIDTH        ([UIScreen mainScreen].bounds.size.width)
// 屏幕高度
//#define SCREEN_HEIGHT       ([UIScreen mainScreen].bounds.size.height)

// 主窗口
#define KEYWINDOW           [UIApplication sharedApplication].keyWindow
// 主视图窗口
#define selfview            self.view


// app版本号
#define DEVICE_APP_VERSION      (NSString *)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]
// app Build版本号
#define DEVICE_APP_BUILD        (NSString *)[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
// 系统版本号(string)
#define DEVICE_OS_VERSION       [[UIDevice currentDevice] systemVersion]
// 系统版本号(float)
#define DEVICE_OS_VERSION_VALUE [DEVICE_OS_VERSION floatValue]
// 字体设置
#define XFont(font)             [UIFont systemFontOfSize:(font)]
//#define XXFont(font)        [UIFont fontWithName:@ "Arial-BoldMT"  size:(font)]
//粗号字体
#define XXFont(font)            [UIFont fontWithName:@ "PingFang SC"  size:(font)]


#define IOS8    [[[UIDevice currentDevice]systemVersion] floatValue] >= 8.0
#define IOS7    [[[UIDevice currentDevice]systemVersion] floatValue] == 7.0
#define IOS9    [[[UIDevice currentDevice]systemVersion] floatValue] >= 9.0
#define IOS10   [[[UIDevice currentDevice]systemVersion] floatValue] >= 10.0
#define IOS10_3 [[[UIDevice currentDevice]systemVersion] floatValue] >= 10.3
#define IOS11   [[[UIDevice currentDevice]systemVersion] floatValue] >= 11.0
#define IOS12   [[[UIDevice currentDevice]systemVersion] floatValue] >= 12.0

#define iPhoneX ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 812)

#define iPhoneXS ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 812)

#define iPhoneXR ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 896)

#define iPhoneXMAX ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 896)

#define iPhone6 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 667)

#define iPhone6Plus ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 736)

#define iPhone5sORiPhone5 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.height) == 568)

#define iPhone4 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 480)

//((kScreenHeight == 812.0 || kScreenHeight == 896.0) ? 88 : 64) //X h=812,XR & XR max h=896


#define STATUS_HEIGHT    [[UIApplication sharedApplication] statusBarFrame].size.height//状态栏高度
#define kStatusBarHegiht ((iPhoneX||iPhoneXR||iPhoneXS||iPhoneXMAX)?44.0f:20.0f)// 顶部安全距离
#define kNavHegiht       ((iPhoneX||iPhoneXR||iPhoneXS||iPhoneXMAX)?88.0f:64.0f)// 导航栏高度
#define kTabbarHeight    ((iPhoneX||iPhoneXR||iPhoneXS||iPhoneXMAX)?83.0f:49.0f)// Tabbar高度
#define KIPHONEXPLUST    SCREEN_HEIGHT >= 812//有刘海屏的iphone手机
#define kSafeHeight      ((KIPHONEXPLUST)?34:0)// 底部安全距离

#define kHeaderViewHeight                  44.0f
#define kTableViewCellHeightSmall          44.0f
#define kTableViewCellHeightMiddle         60.0f

//判断是否模拟器 1 真 0 否
#if TARGET_IPHONE_SIMULATOR
#define SIMULATOR    1
#else
#define SIMULATOR    0
#endif



你可能感兴趣的:(iOS 常用宏定义)