DSBaseModuleInline.h 4.75 KB
//
//  DSBaseModuleInline.h
//  BKProjectFramework
//
//  Created by BIKE on 2018/10/8.
//  Copyright © 2018年 BIKE. All rights reserved.
//

#ifndef DSBaseModuleInline_h
#define DSBaseModuleInline_h

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
/* 编译错误解决:implicit declaration of function 'close' is invalid in C99
 #import <sys/time.h>
 #import <fcntl.h>
 #import <unistd.h>
 */
#import <sys/time.h>
#import <fcntl.h>
#import <unistd.h>

#pragma mark - 检测是否是iPhoneX系列

/**
 判断是否是iPhone X系列
 */
NS_INLINE BOOL DS_is_iPhoneX_series() {
    BOOL iPhoneXSeries = NO;
    if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) {
        return iPhoneXSeries;
    }
    if (@available(iOS 11.0, *)) {
        UIWindow * window = [[[UIApplication sharedApplication] delegate] window];
        if (window.safeAreaInsets.bottom > 0.0) {
            iPhoneXSeries = YES;
        }
    }
    return iPhoneXSeries;
}

/**
 获取系统状态栏高度
 */
NS_INLINE CGFloat DS_get_system_statusBar_height() {
    return DS_is_iPhoneX_series() ? 44.f : 20.f;
}

/**
 获取系统导航高度
 */
NS_INLINE CGFloat DS_get_system_nav_height() {
    return DS_is_iPhoneX_series() ? (44.f+44.f) : 64.f;
}

/**
 获取系统导航UI高度
 */
NS_INLINE CGFloat DS_get_system_nav_ui_height() {
    return DS_get_system_nav_height() - DS_get_system_statusBar_height();
}

/**
 获取系统tabbar高度
 */
NS_INLINE CGFloat DS_get_system_tabbar_height() {
    return DS_is_iPhoneX_series() ? 83.f : 49.f;
}

/**
 获取系统tabbarUI高度
 */
NS_INLINE CGFloat DS_get_system_tabbar_ui_height() {
    return 49.f;
}

/**
 获取系统tabbarUI增加的高度 (因iPhoneX系列底部有安全区域增加的高度)
 */
NS_INLINE CGFloat DS_get_system_tabbar_ui_offsetHeight() {
    return DS_get_system_tabbar_height() - DS_get_system_tabbar_ui_height();
}

#pragma mark - 字体

/**
 细体
 */
UIKIT_STATIC_INLINE UIFont * DS_thin_font(CGFloat pointSize) {
    if (@available(iOS 8.2, *)) {
        return [UIFont systemFontOfSize:pointSize weight:UIFontWeightThin];
    }else {
        return [UIFont systemFontOfSize:pointSize];
    }
}

/**
 半细体
 */
UIKIT_STATIC_INLINE UIFont * DS_light_font(CGFloat pointSize) {
    if (@available(iOS 8.2, *)) {
        return [UIFont systemFontOfSize:pointSize weight:UIFontWeightLight];
    }else {
        return [UIFont systemFontOfSize:pointSize];
    }
}

/**
 正常体
 */
UIKIT_STATIC_INLINE UIFont * DS_regular_font(CGFloat pointSize) {
    if (@available(iOS 8.2, *)) {
        return [UIFont systemFontOfSize:pointSize weight:UIFontWeightRegular];
    }else {
        return [UIFont systemFontOfSize:pointSize];
    }
}

/**
 半粗体
 */
UIKIT_STATIC_INLINE UIFont * DS_medium_font(CGFloat pointSize) {
    if (@available(iOS 8.2, *)) {
        return [UIFont systemFontOfSize:pointSize weight:UIFontWeightMedium];
    }else {
        return [UIFont systemFontOfSize:pointSize];
    }
}

/**
 粗体
 */
UIKIT_STATIC_INLINE UIFont * DS_semibold_font(CGFloat pointSize) {
    if (@available(iOS 8.2, *)) {
        return [UIFont systemFontOfSize:pointSize weight:UIFontWeightSemibold];
    }else {
        return [UIFont boldSystemFontOfSize:pointSize];
    }
}

#pragma mark - 自适应字体

/**
 细体(自适应)
 */
UIKIT_STATIC_INLINE UIFont * DS_thin_adapt_font(CGFloat pointSize) {
    CGFloat multiple = [UIScreen mainScreen].bounds.size.width / 375.0f;
    CGFloat size = floor(pointSize*multiple);
    return DS_thin_font(size);
}

/**
 半细体(自适应)
 */
UIKIT_STATIC_INLINE UIFont * DS_light_adapt_font(CGFloat pointSize) {
    CGFloat multiple = [UIScreen mainScreen].bounds.size.width / 375.0f;
    CGFloat size = floor(pointSize*multiple);
    return DS_light_font(size);
}

/**
 正常体(自适应)
 */
UIKIT_STATIC_INLINE UIFont * DS_regular_adapt_font(CGFloat pointSize) {
    CGFloat multiple = [UIScreen mainScreen].bounds.size.width / 375.0f;
    CGFloat size = floor(pointSize*multiple);
    return DS_regular_font(size);
}

/**
 半粗体(自适应)
 */
UIKIT_STATIC_INLINE UIFont * DS_medium_adapt_font(CGFloat pointSize) {
    CGFloat multiple = [UIScreen mainScreen].bounds.size.width / 375.0f;
    CGFloat size = floor(pointSize*multiple);
    return DS_medium_font(size);
}

/**
 粗体(自适应)
 */
UIKIT_STATIC_INLINE UIFont * DS_semibold_adapt_font(CGFloat pointSize) {
    CGFloat multiple = [UIScreen mainScreen].bounds.size.width / 375.0f;
    CGFloat size = floor(pointSize*multiple);
    return DS_semibold_font(size);
}

#pragma mark - 自适应长度

NS_INLINE CGFloat DS_adapt_length(CGFloat length) {
    CGFloat multiple = [UIScreen mainScreen].bounds.size.width / 375.0f;
    CGFloat f_adapt_length = floor(length * multiple);
    return f_adapt_length;
}

#endif /* DSBaseModuleInline_h */