ifndef __IPHONE_5_0
warning "This project uses features only available in iOS SDK 5.0 and later."
endif
ifdef OBJC
import <UIKit/UIKit.h>
import <Foundation/Foundation.h>
///------
/// Block
///------
typedef void (^VoidBlock)(void);
typedef BOOL (^BoolBlock)(void);
typedef int (^IntBlock) (void);
typedef id (^IDBlock) (void);
typedef void (^VoidBlock_int)(int);
typedef BOOL (^BoolBlock_int)(int);
typedef int (^IntBlock_int) (int);
typedef id (^IDBlock_int) (int);
typedef void (^VoidBlock_string)(NSString *);
typedef BOOL (^BoolBlock_string)(NSString *);
typedef int (^IntBlock_string) (NSString *);
typedef id (^IDBlock_string) (NSString *);
typedef void (^VoidBlock_id)(id);
typedef BOOL (^BoolBlock_id)(id);
typedef int (^IntBlock_id) (id);
typedef id (^IDBlock_id) (id);
define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))
define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)
define MH_IS_IPHONE_X (MH_IS_IPHONE && MH_SCREEN_MAX_LENGTH == 812.0)
/// 导航条高度
define MH_APPLICATION_TOP_BAR_HEIGHT (MH_IS_IPHONE_X?88.0f:64.0f)
/// tabBar高度
define MH_APPLICATION_TAB_BAR_HEIGHT (MH_IS_IPHONE_X?83.0f:49.0f)
/// 工具条高度 (常见的高度)
define MH_APPLICATION_TOOL_BAR_HEIGHT_44 44.0f
define MH_APPLICATION_TOOL_BAR_HEIGHT_49 49.0f
/// 状态栏高度
define MH_APPLICATION_STATUS_BAR_HEIGHT (MH_IS_IPHONE_X?44:20.0f)
// 适配AF
ifndef TARGET_OS_IOS
define TARGET_OS_IOS TARGET_OS_IPHONE
endif
ifndef TARGET_OS_WATCH
define TARGET_OS_WATCH 0
endif
// 输出日志 (格式: [时间] [哪个方法] [哪行] [输出内容])
ifdef DEBUG
define NSLog(format, ...) printf("\n[%s] %s [第%zd行] 💕 %s\n", TIME, FUNCTION, LINE, [[NSString stringWithFormat:format, ##VA_ARGS] UTF8String]);
else
define NSLog(format, ...)
endif
// 日记输出宏
ifdef DEBUG // 调试状态, 打开LOG功能
define MHLog(...) NSLog(VA_ARGS)
else // 发布状态, 关闭LOG功能
define MHLog(...)
endif
// 打印方法
define MHLogFunc MHLog(@"%s", func)
// 打印请求错误信息
define MHLogErrorMessage MHLog(@"错误请求日志-----【 %@ 】--【 %@ 】",[self class] , error.mh_message)
// KVO获取监听对象的属性 有自动提示
// 宏里面的#,会自动把后面的参数变成c语言的字符串
define MHKeyPath(objc,keyPath) @(((void)objc.keyPath ,#keyPath))
// 颜色
define MHColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
// 颜色+透明度
define MHAlphaColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:a]
// 随机色
define MHRandomColor MHColor(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))
// 根据rgbValue获取值
define MHColorFromRGB(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]
// 是否为iOS7+
define MHIOS7 ([[UIDevice currentDevice].systemVersion doubleValue] >= 7.0)
// 是否为4inch
define MHFourInch ([UIScreen mainScreen].bounds.size.height == 568.0)
// 屏幕总尺寸
define MHMainScreenBounds [UIScreen mainScreen].bounds
define MHMainScreenHeight [UIScreen mainScreen].bounds.size.height
define MHMainScreenWidth [UIScreen mainScreen].bounds.size.width
// IOS版本
define MHIOSVersion [[[UIDevice currentDevice] systemVersion] floatValue]
// 销毁打印
define MHDealloc MHLog(@"\n =========+++ %@ 销毁了 +++======== \n",[self class])
// 是否为空对象
define MHObjectIsNil(__object) ((nil == __object) || [__object isKindOfClass:[NSNull class]])
// 字符串为空
define MHStringIsEmpty(__string) ((__string.length == 0) || MHObjectIsNil(__string))
// 字符串不为空
define MHStringIsNotEmpty(__string) (!MHStringIsEmpty(__string))
// 数组为空
define MHArrayIsEmpty(__array) ((MHObjectIsNil(__array)) || (__array.count==0))
// 取消ios7以后下移
define MHDisabledAutomaticallyAdjustsScrollViewInsets \
if (MHIOSVersion>=7.0) {
self.automaticallyAdjustsScrollViewInsets = NO;
}
// AppCaches 文件夹路径
define MHCachesDirectory [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]
// App DocumentDirectory 文件夹路径
define MHDocumentDirectory [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) lastObject]
// 系统放大倍数
define MHScale [[UIScreen mainScreen] scale]
/**
- Frame PX ---> Pt 6的宽度 全部向下取整数
*/
define MHPxConvertPt(__Px) floor((__Px) * MHMainScreenWidth/375.0f)
/**
- Frame PX ---> Pt 6的宽度 返回一个合适的值 按钮手指触摸点 44
*/
define MHFxConvertFitPt(__px) (MAX(MHPxConvertPt(__Px),44))
// 设置图片
define MHImageNamed(__imageName) [UIImage imageNamed:__imageName]
/// 适配iPhone X + iOS 11
define MHAdjustsScrollViewInsets_Never(__scrollView)\
do {
_Pragma("clang diagnostic push")
_Pragma("clang diagnostic ignored "-Warc-performSelector-leaks"")
if ([__scrollView respondsToSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:")]) {
NSMethodSignature *signature = [UIScrollView instanceMethodSignatureForSelector:@selector(setContentInsetAdjustmentBehavior:)];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
NSInteger argument = 2;
invocation.target = __scrollView;
invocation.selector = @selector(setContentInsetAdjustmentBehavior:);
[invocation setArgument:&argument atIndex:2];
[invocation retainArguments];
[invocation invoke];
}
_Pragma("clang diagnostic pop")
} while (0)
// 常用的