220 lines
8.1 KiB
C
Executable File
220 lines
8.1 KiB
C
Executable File
//
|
||
// YYUtilsMacros.h
|
||
// idleBuy
|
||
//
|
||
// Created by ios on 2018/5/28.
|
||
// Copyright © 2018年 ios. All rights reserved.
|
||
//
|
||
|
||
#ifndef YYUtilsMacros_h
|
||
#define YYUtilsMacros_h
|
||
|
||
|
||
|
||
//#define CQHttp @""//正式
|
||
|
||
|
||
|
||
//#define CQHttp @"https://cqyt.test.yg.icdat.cn"//
|
||
|
||
//获取系统对象
|
||
|
||
#define IOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
|
||
#define IOS8 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
|
||
#define iOS9Later ([UIDevice currentDevice].systemVersion.floatValue >= 9.0f)
|
||
|
||
#define kApplication [UIApplication sharedApplication]
|
||
#define kAppWindow [UIApplication sharedApplication].delegate.window
|
||
#define kAppDelegate [AppDelegate shareAppDelegate]
|
||
#define kRootViewController [UIApplication sharedApplication].delegate.window.rootViewController
|
||
#define kUserDefaults [NSUserDefaults standardUserDefaults]
|
||
#define kNotificationCenter [NSNotificationCenter defaultCenter]
|
||
|
||
#define kStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
|
||
#define kNavBarHeight 44.0
|
||
#define kTabBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height>20?83:49)
|
||
#define kTopHeight (kStatusBarHeight + kNavBarHeight)
|
||
/* 系统版本和语言 */
|
||
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
|
||
#define CurrentSystemVersion ([[UIDevice currentDevice] systemVersion])
|
||
#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
|
||
#define IPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
|
||
|
||
#define IOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
|
||
#define IOS8 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
|
||
#define iOS9Later ([UIDevice currentDevice].systemVersion.floatValue >= 9.0f)
|
||
#define IPHONE4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
|
||
//判断是否是IPHONE5的宏,用法是 if(IPHONE) xxxx else xxxxx
|
||
#define IPHONE5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
|
||
|
||
/* 判断iphonex*/
|
||
#define IPHONE_X \
|
||
({BOOL isPhoneX = NO;\
|
||
if (@available(iOS 11.0, *)) {\
|
||
isPhoneX = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0;\
|
||
}\
|
||
(isPhoneX);})
|
||
|
||
|
||
|
||
/* 宽度*/
|
||
#define SCREEN_BOUNDS [[UIScreen mainScreen]bounds]
|
||
#define WIDTH [[UIScreen mainScreen]bounds].size.width
|
||
#define HEIGHT [[UIScreen mainScreen]bounds].size.height
|
||
#define SCREEN_SIZE [[UIScreen mainScreen]bounds].size
|
||
#define STATUSBAR_HEIGHT [[UIApplication sharedApplication]statusBarFrame].size.height
|
||
#define STATUSBAR_WIDTH [[UIApplication sharedApplication]statusBarFrame].size.width
|
||
#define mykeyWindow [UIApplication sharedApplication].delegate.window
|
||
#define HEIGHT_6_SCALE HEIGHT/667
|
||
#define IS_IPHONE_6P (WIDTH > 375)
|
||
#define myScale6 WIDTH/375
|
||
#define HEIGHT_TABBAR (IPHONE_X ? 83 : 49)
|
||
#define HEIGHT_NAVIGATION (IPHONE_X ? 88 : 64)
|
||
#define SafetyAreaHeight (IPHONE_X ? 24 : 0)
|
||
#define HomeHEIGHT (HEIGHT - HEIGHT_NAVIGATION - HEIGHT_TABBAR)
|
||
#define MyViewHEIGHT (HEIGHT - HEIGHT_NAVIGATION)
|
||
#define KNavigationBarHeight (44.0)
|
||
#define KStatusBarHeight ([UIApplication sharedApplication].statusBarFrame.size.height)
|
||
#define KTopHeight (KNavigationBarHeight + KStatusBarHeight)
|
||
#define LineSpace 5
|
||
//根据ip6的屏幕来拉伸
|
||
#define kRealValue(with) ((with)*(WIDTH/375.0f))
|
||
|
||
//强弱引用
|
||
#define kWeakSelf(type) __weak typeof(type) weak##type = type;
|
||
#define kStrongSelf(type) __strong typeof(type) type = weak##type;
|
||
|
||
//View 圆角和加边框
|
||
#define ViewBorderRadius(View, Radius, Width, Color)\
|
||
\
|
||
[View.layer setCornerRadius:(Radius)];\
|
||
[View.layer setMasksToBounds:YES];\
|
||
[View.layer setBorderWidth:(Width)];\
|
||
[View.layer setBorderColor:[Color CGColor]]
|
||
|
||
// View 圆角
|
||
#define ViewRadius(View, Radius)\
|
||
\
|
||
[View.layer setCornerRadius:(Radius)];\
|
||
[View.layer setMasksToBounds:YES]
|
||
//字体
|
||
#define BOLDSYSTEMFONT(FONTSIZE)[UIFont boldSystemFontOfSize:FONTSIZE]
|
||
#define SYSTEMFONT(FONTSIZE) [UIFont systemFontOfSize:FONTSIZE]
|
||
#define FONT(NAME, FONTSIZE) [UIFont fontWithName:(NAME) size:(FONTSIZE)]
|
||
#define MEDIUMFONT(FONTSIZE) [UIFont systemFontOfSize:FONTSIZE weight:UIFontWeightMedium];
|
||
|
||
#define PLACEHOLD_IMG IMAGE_NAMED(@"placeholdIMG")
|
||
|
||
|
||
#define IMAGE_NAMED(name) [UIImage imageNamed:name]
|
||
/**
|
||
* the saving objects 存储对象
|
||
*
|
||
* @param __VALUE__ V
|
||
* @param __KEY__ K
|
||
*
|
||
* @return
|
||
*/
|
||
#define UserDefaultSetObjectForKey(__VALUE__,__KEY__) \
|
||
{\
|
||
[[NSUserDefaults standardUserDefaults] setObject:__VALUE__ forKey:__KEY__];\
|
||
[[NSUserDefaults standardUserDefaults] synchronize];\
|
||
}
|
||
|
||
/**
|
||
* get the saved objects 获得存储的对象
|
||
*/
|
||
#define UserDefaultObjectForKey(__KEY__) [[NSUserDefaults standardUserDefaults] objectForKey:__KEY__]
|
||
|
||
/**
|
||
* delete objects 删除对象
|
||
*/
|
||
#define UserDefaultRemoveObjectForKey(__KEY__) \
|
||
{\
|
||
[[NSUserDefaults standardUserDefaults] removeObjectForKey:__KEY__];\
|
||
[[NSUserDefaults standardUserDefaults] synchronize];\
|
||
}
|
||
///IOS 版本判断
|
||
#define IOSAVAILABLEVERSION(version) ([[UIDevice currentDevice] availableVersion:version] < 0)
|
||
// 当前系统版本
|
||
#define CurrentSystemVersion [[UIDevice currentDevice].systemVersion doubleValue]
|
||
//当前语言
|
||
#define CurrentLanguage ([NSLocale preferredLanguages] objectAtIndex:0])
|
||
|
||
//-------------------打印日志-------------------------
|
||
//DEBUG 模式下打印日志,当前行
|
||
#ifdef DEBUG
|
||
#define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
|
||
#else
|
||
#define DLog(...)
|
||
#endif
|
||
//颜色
|
||
#define KClearColor [UIColor clearColor]
|
||
#define KWhiteColor [UIColor whiteColor]
|
||
#define KBlackColor [UIColor blackColor]
|
||
#define KGrayColor [UIColor grayColor]
|
||
#define KGray2Color [UIColor lightGrayColor]
|
||
#define KBlueColor [UIColor blueColor]
|
||
#define KRedColor [UIColor redColor]
|
||
#define RGBA(r,g,b,a) ([UIColor colorWithRed:r/255.0 \
|
||
green:g/255.0 \
|
||
blue:b/255.0 \
|
||
alpha:a])
|
||
#define RGB(r,g,b) (RGBA(r,g,b,1))
|
||
|
||
#define RGB_VALUE(value) ([UIColor colorWithRed:((float)((value&0xFF0000)>>16))/255.0f \
|
||
green:((float)((value&0xFF00)>>8))/255.0f \
|
||
blue:((float)(value&0xFF))/255.0f \
|
||
alpha:1.0f])
|
||
#define Kcustom_color(R,G,B) ([UIColor colorWithRed:(R)/255.0 \
|
||
green:(G)/255.0 \
|
||
blue:(B)/255.0 \
|
||
alpha:1.0])
|
||
|
||
#define UIColorBackground (RGB(243,244,246))
|
||
#define UIColorTitle1 (RGB_VALUE(0x333333))
|
||
#define UIColorTitle2 (RGB_VALUE(0x666666))
|
||
#define UIColorTitle3 (RGB_VALUE(0x999999))
|
||
#define UITextBackColor (RGBA(169,169,169,1))
|
||
#define UIWhiteColor ([UIColor whiteColor])
|
||
#define UIColorLine (RGB_VALUE(0xE5E5E5))
|
||
#define UIColorTheme (RGB(242,48,48))
|
||
#define UIGreenColor (RGB(123,209,132))
|
||
#define UIColorMain (RGB(189,19,11))
|
||
|
||
//数据验证
|
||
#define StrValid(f) ([f isKindOfClass:[NSNull class]] || f == nil || [f length] < 1 || [f isEqualToString:@"(null)"] || [f isEqualToString:@"<null>"] || [f isEqualToString:@"null"]? YES : NO)
|
||
|
||
#define ValidStr(f) StrValid(f)
|
||
|
||
#define SafeStr(f) (!StrValid(f) ? f:@"-")
|
||
#define HasString(str,key) ([str rangeOfString:key].location!=NSNotFound)
|
||
|
||
#define ValidDict(f) (f!=nil && [f isKindOfClass:[NSDictionary class]])
|
||
#define ValidArray(f) (f!=nil && [f isKindOfClass:[NSArray class]] && [f count]>0)
|
||
#define ValidNum(f) (f!=nil && [f isKindOfClass:[NSNumber class]])
|
||
#define ValidClass(f,cls) (f!=nil && [f isKindOfClass:[cls class]])
|
||
#define ValidData(f) (f!=nil && [f isKindOfClass:[NSData class]])
|
||
//拼接字符串
|
||
#define NSStringFormat(format,...) [NSString stringWithFormat:format,##__VA_ARGS__]
|
||
//发送通知
|
||
#define KPostNotification(name,obj) [[NSNotificationCenter defaultCenter] postNotificationName:name object:obj];
|
||
//单例化一个类
|
||
#define SINGLETON_FOR_HEADER(className) \
|
||
\
|
||
+ (className *)shared##className;
|
||
|
||
#define SINGLETON_FOR_CLASS(className) \
|
||
\
|
||
+ (className *)shared##className { \
|
||
static className *shared##className = nil; \
|
||
static dispatch_once_t onceToken; \
|
||
dispatch_once(&onceToken, ^{ \
|
||
shared##className = [[self alloc] init]; \
|
||
}); \
|
||
return shared##className; \
|
||
}
|
||
|
||
|
||
#endif /* YYUtilsMacros_h */
|