iOS 规范之宏

#pragma mark ============= 适配11系统   Available in iOS 7.0 and later.  =============

简单点说就是automaticallyAdjustsScrollViewInsets根据按所在界面的status bar,navigationbar,与tabbar的高度,自动调整scrollview的 inset,设置为no,不让viewController调整,我们自己修改布局

/**iOS 11 automaticallyAdjustsScrollViewInsets的问题*/

#define  adjustsScrollViewInsets_NO(scrollView,vc)

_Pragma("clang diagnostic push")

_Pragma("clang diagnostic ignored "-Wdeprecated-declarations"")

if (@available(iOS 11.0,*))  {

scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;

} else {

self.automaticallyAdjustsScrollViewInsets = NO;

}

_Pragma("clang diagnostic pop")

#pragma mark ============= 方正黑体简体字体定义  =============

#define XH_FONT(__SIZE__) [UIFont fontWithName:@"FZHTJW--GB1-0" size:__SIZE__]

#pragma mark ============= DEBUG  模式下打印日志,当前行  =============

#ifdef DEBUG

#   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

#else

#   define DLog(...)

#endif

#pragma mark ============= 重写NSLog,Debug模式下打印日志和当前行数  =============

#if DEBUG

#define NSLog(FORMAT, ...) fprintf(stderr," function:%s line:%d content:%s ", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);

#else

#define NSLog(FORMAT, ...) nil

#endif

#pragma mark ============= 获取系统版本  =============

#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]

#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]

#pragma mark ============= 获取当前语言  =============

#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

#pragma mark ============= rgb颜色转换(16进制->10进制) =============

#define UIColorFromRGB(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]

#pragma mark ============= 单例化一个类 =============

#define SYNTHESIZE_SINGLETON_FOR_CLASS(classname)

static classname *shared##classname = nil;

+ (classname *)shared##classname

{

@synchronized(self)

{

if (shared##classname == nil)

{

shared##classname = [[self alloc] init];

}

}

return shared##classname;

}

+ (id)allocWithZone:(NSZone *)zone

{

@synchronized(self)

{

if (shared##classname == nil)

{

shared##classname = [super allocWithZone:zone];

return shared##classname;

}

}

return nil;

}

- (id)copyWithZone:(NSZone *)zone

{

return self;

}

#pragma mark ============= 适配各手机屏幕 =============

#import <UIKit/UIKit.h>

UIKIT_STATIC_INLINE CGFloat CGFloatBasedI375(CGFloat size) {
// 对齐到2倍数
return trunc(size * UIScreen.mainScreen.bounds.size.width / 375 * 2) / 2.0;
}

#pragma mark ============= 弱引用 =============

#define WS(weakself) __weak __typeof(&*self)weakself = self

原文地址:https://www.cnblogs.com/liaolijun/p/7886197.html