DSBaseModuleInline.h
4.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//
// 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 */