SystemMacro.h 5.75 KB
//
//  SystemMacro.h
//  CNLiveScioLive
//
//  Created by CNLive-zxw on 2018/9/18.
//  Copyright © 2018年 CNLive. All rights reserved.
//

#ifndef SystemMacro_h
#define SystemMacro_h

#ifndef AppKeyWindow
#define AppKeyWindow ((AppDelegate *)[UIApplication sharedApplication].delegate).window
#endif

//协议调取方法
#define CNMessageSend(instance,protocol,message) [(id<protocol>)(instance) message]

// 系统语言
#define SYSTEM_LANGUAGE [[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] objectAtIndex:0]
#define IS_CHINESE ([SYSTEM_LANGUAGE isEqualToString:@"zh-Hans-CN"]||[SYSTEM_LANGUAGE isEqualToString:@"zh-Hant-CN"]||[SYSTEM_LANGUAGE isEqualToString:@"zh-Hans"] ||[SYSTEM_LANGUAGE isEqualToString:@"zh-hans"])
#define Language_Local @"Language_Local"

#define CustomStr(key) [(AppDelegate *)[[UIApplication sharedApplication] delegate] showText:(key)]

#define lan_html (IS_CHINESE ? @"zh" : @"en")

//支持的语言包
#define HasSupportedLocalizedResource ([SYSTEM_LANGUAGE hasPrefix:@"zh"])

//国际化的宏
#define EQDLocalizedString(key, comment) \
(HasSupportedLocalizedResource?([[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]):([[NSBundle bundleWithPath:BundlePath(@"en", @"lproj")] localizedStringForKey:key value:@"" table:nil]))

/**
 系统及设备
 */
#define iOS7 [[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0
#define iOS8 [[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0
#define iOS9 [[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0
#define iOS6 [[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0 && [[[UIDevice currentDevice] systemVersion] floatValue] < 7.0
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define iTouch ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(320, 480), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone6Plus ((ScreenWidth==414)?YES:NO)
#define iPhone6   ((ScreenWidth==375)?YES:NO)
#define iPhone320 ((ScreenWidth==320)?YES:NO)
#define iPhone4 ((ScreenHeight==480)?YES:NO)
//适配iphoex
//#define iPhoneX ((MainScreenHeight == 812.0f) ? YES : NO)
// 是否是iPhone X系列
#define iPhoneX       ([UIScreen instancesRespondToSelector:@selector(currentMode)] ?\
(\
CGSizeEqualToSize(CGSizeMake(375, 812),[UIScreen mainScreen].bounds.size)\
||\
CGSizeEqualToSize(CGSizeMake(812, 375),[UIScreen mainScreen].bounds.size)\
||\
CGSizeEqualToSize(CGSizeMake(414, 896),[UIScreen mainScreen].bounds.size)\
||\
CGSizeEqualToSize(CGSizeMake(896, 414),[UIScreen mainScreen].bounds.size))\
:\
NO)

//区分真机还是模拟器

#if TARGET_IPHONE_SIMULATOR//模拟器

#define SIMULATOR 1

#elif TARGET_OS_IPHONE//真机

#define SIMULATOR 0

#endif

/**
 *  适配
 */
#define MainScale                           MainScreenWidth/375.f
#define MainHScale                          MainScreenHeight/667.f
#define NavBarHeight                        ((iPhoneX==YES) ? 88.0f: 64.0f)
#define StatusBarHeight                     ((iPhoneX==YES) ? 44.0f: 20.0f)
#define TabBarHeight                        ((iPhoneX==YES) ? 83.0f: 49.0f)
#define MainScreenWidth                     [[UIScreen mainScreen] bounds].size.width
#define MainScreenHeight                    [[UIScreen mainScreen] bounds].size.height

#define NavBarContentHeight                 44.0f

/**
 *  系统方法
 */
#define WS(weakSelf)                         __weak __typeof(&*self)weakSelf = self;
#define Notification_Center                  [NSNotificationCenter defaultCenter]
#define Application_Delegate                 ((AppDelegate *)[[UIApplication sharedApplication] delegate])
#define KeyWindowRootController              [[[UIApplication sharedApplication] keyWindow] rootViewController]
#define NS_Bundle                            [NSBundle mainBundle]
#define User_Defaults                        [NSUserDefaults standardUserDefaults]

#define LoginSuccessful                        @"LoginSuccessful"
#define ExitSuccessful                         @"ExitSuccessful"
#define GetCodeSuccessful                      @"GetCodeSuccessful"
#define ISGRAYMODE                             @"isGrayMode"
#define HOMETITLECOLOR                         @"homeTitleColor"

#define HOMETITLECOLORSTR   [[NSUserDefaults standardUserDefaults] valueForKey:HOMETITLECOLOR]
//图片
#define Image(image)  [UIImage imageNamed:image]

//字体
#define Font(size)  [UIFont systemFontOfSize:size]
#define BFont(size) [UIFont boldSystemFontOfSize:size]

//颜色
#define HEXCOLOR(c)                         [UIColor colorWithRed:((c>>16)&0xFF)/255.0 green:((c>>8)&0xFF)/255.0 blue:(c&0xFF)/255.0 alpha:1.0]
#define HEXCOLORA(c,a)                      [UIColor colorWithRed:((c>>16)&0xFF)/255.0 green:((c>>8)&0xFF)/255.0 blue:(c&0xFF)/255.0 alpha:a]


/**
 *  16进制转化颜色
 */
#define UIColorFromRGB(rgbValue,A) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:A]
/**
 * 定义Rect
 */
#define rect(x,y,w,h) CGRectMake(x,y,w,h)
/**
 * 定义point
 */
#define point(x,y) CGPointMake(x,y)
/**
 * 定义size
 */
#define size(w,h) CGSizeMake(w,h)
/**
 *  获取最大X,Y
 */
#define maxX(rect) CGRectGetMaxX(rect)
#define maxY(rect) CGRectGetMaxY(rect)
/**
 *  获取最小X,Y
 */
#define minX(rect) CGRectGetMinX(rect)
#define minY(rect) CGRectGetMinY(rect)
/**
 *  获取矩形宽,高
 */
#define rectW(rect) CGRectGetWidth(rect)
#define rectH(rect) CGRectGetHeight(rect)

#define cellItemWidth (MainScreenWidth - 24)
#define cellItemHeight (cellItemWidth*5/8)
#define leftImageCellWidth (MainScreenWidth*3/8)
#define threeImageCellWidth ((cellItemWidth - 16)/3)

#endif /* SystemMacro_h */