forked from Tencent/QMUI_iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQMUIConfiguration.m
530 lines (456 loc) · 25.8 KB
/
QMUIConfiguration.m
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
/*****
* Tencent is pleased to support the open source community by making QMUI_iOS available.
* Copyright (C) 2016-2018 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*****/
//
// QMUIConfiguration.m
// qmui
//
// Created by QMUI Team on 15/3/29.
//
#import "QMUIConfiguration.h"
#import "QMUICore.h"
#import "UIImage+QMUI.h"
#import "NSString+QMUI.h"
#import "UIViewController+QMUI.h"
#import "QMUIKit.h"
#import <objc/runtime.h>
// 在 iOS 8 - 11 上实际测量得到
// Measured on iOS 8 - 11
const CGSize kUINavigationBarBackIndicatorImageSize = {13, 21};
@implementation QMUIConfiguration
+ (instancetype)sharedInstance {
static dispatch_once_t pred;
static QMUIConfiguration *sharedInstance;
dispatch_once(&pred, ^{
sharedInstance = [[QMUIConfiguration alloc] init];
});
return sharedInstance;
}
- (instancetype)init {
self = [super init];
if (self) {
[self initDefaultConfiguration];
}
return self;
}
static BOOL QMUI_hasAppliedInitialTemplate;
- (void)applyInitialTemplate {
if (QMUI_hasAppliedInitialTemplate) {
return;
}
// 自动寻找并应用模板
// Automatically look for templates and apply them
// @see https://github.com/QMUI/QMUI_iOS/issues/264
Protocol *protocol = @protocol(QMUIConfigurationTemplateProtocol);
int numberOfClasses = objc_getClassList(NULL, 0);
if (numberOfClasses > 0) {
Class *classes = (__unsafe_unretained Class *)malloc(sizeof(Class) * numberOfClasses);
numberOfClasses = objc_getClassList(classes, numberOfClasses);
for (int i = 0; i < numberOfClasses; i++) {
Class class = classes[i];
// 这里用 containsString 是考虑到 Swift 里 className 由“项目前缀+class 名”组成,如果用 hasPrefix 就无法判断了
// Use `containsString` instead of `hasPrefix` because class names in Swift have project prefix prepended
if ([NSStringFromClass(class) containsString:@"QMUIConfigurationTemplate"] && [class conformsToProtocol:protocol]) {
if ([class instancesRespondToSelector:@selector(shouldApplyTemplateAutomatically)]) {
id<QMUIConfigurationTemplateProtocol> template = [[class alloc] init];
if ([template shouldApplyTemplateAutomatically]) {
QMUI_hasAppliedInitialTemplate = YES;
[template applyConfigurationTemplate];
_active = YES;// 标志配置表已生效
// 只应用第一个 shouldApplyTemplateAutomatically 的主题
// Only apply the first template returned
break;
}
}
}
}
free(classes);
}
if (IS_DEBUG && self.sendAnalyticsToQMUITeam) {
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidFinishLaunchingNotification object:nil queue:[NSOperationQueue new] usingBlock:^(NSNotification * _Nonnull note) {
[self sendAnalytics];
}];
}
QMUI_hasAppliedInitialTemplate = YES;
}
- (void)sendAnalytics {
NSString *identifier = [NSBundle mainBundle].bundleIdentifier.qmui_stringByEncodingUserInputQuery;
NSString *displayName = ((NSString *)([NSBundle mainBundle].infoDictionary[@"CFBundleDisplayName"] ?: [NSBundle mainBundle].infoDictionary[@"CFBundleName"])).qmui_stringByEncodingUserInputQuery;
NSString *QMUIVersion = QMUI_VERSION.qmui_stringByEncodingUserInputQuery;// 如果不以 framework 方式引入 QMUI 的话,是无法通过 CFBundleShortVersionString 获取到 QMUI 所在的 bundle 的版本号的,所以这里改为用脚本生成的变量来获取
NSString *appInfo = [NSString stringWithFormat:@"appId=%@&appName=%@&version=%@&platform=iOS", identifier, displayName, QMUIVersion];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://qmuiteam.com/analytics/usageReport"]];
request.HTTPMethod = @"POST";
request.HTTPBody = [appInfo dataUsingEncoding:NSUTF8StringEncoding];
NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithRequest:request] resume];
}
#pragma mark - Initialize default values
- (void)initDefaultConfiguration {
#pragma mark - Global Color
self.clearColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0];
self.whiteColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
self.blackColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
self.grayColor = UIColorMake(179, 179, 179);
self.grayDarkenColor = UIColorMake(163, 163, 163);
self.grayLightenColor = UIColorMake(198, 198, 198);
self.redColor = UIColorMake(250, 58, 58);
self.greenColor = UIColorMake(159, 214, 97);
self.blueColor = UIColorMake(49, 189, 243);
self.yellowColor = UIColorMake(255, 207, 71);
self.linkColor = UIColorMake(56, 116, 171);
self.disabledColor = self.grayColor;
self.backgroundColor = nil;
self.maskDarkColor = UIColorMakeWithRGBA(0, 0, 0, .35f);
self.maskLightColor = UIColorMakeWithRGBA(255, 255, 255, .5f);
self.separatorColor = UIColorMake(222, 224, 226);
self.separatorDashedColor = UIColorMake(17, 17, 17);
self.placeholderColor = UIColorMake(196, 200, 208);
self.testColorRed = UIColorMakeWithRGBA(255, 0, 0, .3);
self.testColorGreen = UIColorMakeWithRGBA(0, 255, 0, .3);
self.testColorBlue = UIColorMakeWithRGBA(0, 0, 255, .3);
#pragma mark - UIControl
self.controlHighlightedAlpha = 0.5f;
self.controlDisabledAlpha = 0.5f;
#pragma mark - UIButton
self.buttonHighlightedAlpha = self.controlHighlightedAlpha;
self.buttonDisabledAlpha = self.controlDisabledAlpha;
self.buttonTintColor = self.blueColor;
self.ghostButtonColorBlue = self.blueColor;
self.ghostButtonColorRed = self.redColor;
self.ghostButtonColorGreen = self.greenColor;
self.ghostButtonColorGray = self.grayColor;
self.ghostButtonColorWhite = self.whiteColor;
self.fillButtonColorBlue = self.blueColor;
self.fillButtonColorRed = self.redColor;
self.fillButtonColorGreen = self.greenColor;
self.fillButtonColorGray = self.grayColor;
self.fillButtonColorWhite = self.whiteColor;
#pragma mark - UITextField & UITextView
self.textFieldTintColor = nil;
self.textFieldTextInsets = UIEdgeInsetsMake(0, 7, 0, 7);
#pragma mark - NavigationBar
self.navBarHighlightedAlpha = 0.2f;
self.navBarDisabledAlpha = 0.2f;
self.navBarButtonFont = nil;
self.navBarButtonFontBold = nil;
self.navBarBackgroundImage = nil;
self.navBarShadowImage = nil;
self.navBarBarTintColor = nil;
self.navBarTintColor = nil;
self.navBarTitleColor = nil;
self.navBarTitleFont = nil;
self.navBarLargeTitleColor = nil;
self.navBarLargeTitleFont = nil;
self.navBarBackButtonTitlePositionAdjustment = UIOffsetZero;
self.sizeNavBarBackIndicatorImageAutomatically = YES;
self.navBarBackIndicatorImage = nil;
self.navBarCloseButtonImage = [UIImage qmui_imageWithShape:QMUIImageShapeNavClose size:CGSizeMake(16, 16) tintColor:self.navBarTintColor];
self.navBarLoadingMarginRight = 3;
self.navBarAccessoryViewMarginLeft = 5;
self.navBarActivityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
self.navBarAccessoryViewTypeDisclosureIndicatorImage = [[UIImage qmui_imageWithShape:QMUIImageShapeTriangle size:CGSizeMake(8, 5) tintColor:self.navBarTitleColor] qmui_imageWithOrientation:UIImageOrientationDown];
#pragma mark - TabBar
self.tabBarBackgroundImage = nil;
self.tabBarBarTintColor = nil;
self.tabBarShadowImageColor = nil;
self.tabBarTintColor = nil;
self.tabBarItemTitleColor = nil;
self.tabBarItemTitleColorSelected = self.tabBarTintColor;
self.tabBarItemTitleFont = nil;
#pragma mark - Toolbar
self.toolBarHighlightedAlpha = 0.4f;
self.toolBarDisabledAlpha = 0.4f;
self.toolBarTintColor = nil;
self.toolBarTintColorHighlighted = [self.toolBarTintColor colorWithAlphaComponent:self.toolBarHighlightedAlpha];
self.toolBarTintColorDisabled = [self.toolBarTintColor colorWithAlphaComponent:self.toolBarDisabledAlpha];
self.toolBarBackgroundImage = nil;
self.toolBarBarTintColor = nil;
self.toolBarShadowImageColor = nil;
self.toolBarButtonFont = nil;
#pragma mark - SearchBar
self.searchBarTextFieldBackground = nil;
self.searchBarTextFieldBorderColor = nil;
self.searchBarBottomBorderColor = nil;
self.searchBarBarTintColor = nil;
self.searchBarTintColor = nil;
self.searchBarTextColor = nil;
self.searchBarPlaceholderColor = self.placeholderColor;
self.searchBarFont = nil;
self.searchBarSearchIconImage = nil;
self.searchBarClearIconImage = nil;
self.searchBarTextFieldCornerRadius = 2.0;
#pragma mark - TableView / TableViewCell
self.tableViewEstimatedHeightEnabled = YES;
self.tableViewBackgroundColor = nil;
self.tableViewGroupedBackgroundColor = nil;
self.tableSectionIndexColor = nil;
self.tableSectionIndexBackgroundColor = nil;
self.tableSectionIndexTrackingBackgroundColor = nil;
self.tableViewSeparatorColor = self.separatorColor;
self.tableViewCellNormalHeight = UITableViewAutomaticDimension;
self.tableViewCellTitleLabelColor = nil;
self.tableViewCellDetailLabelColor = nil;
self.tableViewCellBackgroundColor = self.whiteColor;
self.tableViewCellSelectedBackgroundColor = UIColorMake(238, 239, 241);
self.tableViewCellWarningBackgroundColor = self.yellowColor;
self.tableViewCellDisclosureIndicatorImage = nil;
self.tableViewCellCheckmarkImage = nil;
self.tableViewCellDetailButtonImage = nil;
self.tableViewCellSpacingBetweenDetailButtonAndDisclosureIndicator = 12;
self.tableViewSectionHeaderBackgroundColor = UIColorMake(244, 244, 244);
self.tableViewSectionFooterBackgroundColor = UIColorMake(244, 244, 244);
self.tableViewSectionHeaderFont = UIFontBoldMake(12);
self.tableViewSectionFooterFont = UIFontBoldMake(12);
self.tableViewSectionHeaderTextColor = self.grayDarkenColor;
self.tableViewSectionFooterTextColor = self.grayColor;
self.tableViewSectionHeaderAccessoryMargins = UIEdgeInsetsMake(0, 15, 0, 0);
self.tableViewSectionFooterAccessoryMargins = UIEdgeInsetsMake(0, 15, 0, 0);
self.tableViewSectionHeaderContentInset = UIEdgeInsetsMake(4, 15, 4, 15);
self.tableViewSectionFooterContentInset = UIEdgeInsetsMake(4, 15, 4, 15);
self.tableViewGroupedSectionHeaderFont = UIFontMake(12);
self.tableViewGroupedSectionFooterFont = UIFontMake(12);
self.tableViewGroupedSectionHeaderTextColor = self.grayDarkenColor;
self.tableViewGroupedSectionFooterTextColor = self.grayColor;
self.tableViewGroupedSectionHeaderAccessoryMargins = UIEdgeInsetsMake(0, 15, 0, 0);
self.tableViewGroupedSectionFooterAccessoryMargins = UIEdgeInsetsMake(0, 15, 0, 0);
self.tableViewGroupedSectionHeaderDefaultHeight = UITableViewAutomaticDimension;
self.tableViewGroupedSectionFooterDefaultHeight = UITableViewAutomaticDimension;
self.tableViewGroupedSectionHeaderContentInset = UIEdgeInsetsMake(16, 15, 8, 15);
self.tableViewGroupedSectionFooterContentInset = UIEdgeInsetsMake(8, 15, 2, 15);
#pragma mark - UIWindowLevel
self.windowLevelQMUIAlertView = UIWindowLevelAlert - 4.0;
#pragma mark - QMUILog
self.shouldPrintDefaultLog = YES;
self.shouldPrintInfoLog = YES;
self.shouldPrintWarnLog = YES;
#pragma mark - Others
self.automaticCustomNavigationBarTransitionStyle = NO;
self.supportedOrientationMask = UIInterfaceOrientationMaskAll;
self.automaticallyRotateDeviceOrientation = NO;
self.statusbarStyleLightInitially = NO;
self.needsBackBarButtonItemTitle = NO;
self.hidesBottomBarWhenPushedInitially = NO;
self.preventConcurrentNavigationControllerTransitions = YES;
self.navigationBarHiddenInitially = NO;
self.shouldFixTabBarTransitionBugInIPhoneX = NO;
self.shouldAssertResizableImageCapInsetsError = NO;
self.sendAnalyticsToQMUITeam = YES;
}
- (void)setNavBarButtonFont:(UIFont *)navBarButtonFont {
_navBarButtonFont = navBarButtonFont;
// by molice 2017-08-04 只要用 appearence 的方式修改 UIBarButtonItem 的 font,就会导致界面切换时 UIBarButtonItem 抖动,系统的问题,所以暂时不修改 appearance。
// by molice 2018-06-14 iOS 11 观察貌似又没抖动了,先试试看
if (navBarButtonFont) {
UIBarButtonItem *barButtonItemAppearance = [UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil];
NSDictionary<NSAttributedStringKey,id> *attributes = @{NSFontAttributeName: navBarButtonFont};
[barButtonItemAppearance setTitleTextAttributes:attributes forState:UIControlStateNormal];
[barButtonItemAppearance setTitleTextAttributes:attributes forState:UIControlStateHighlighted];
[barButtonItemAppearance setTitleTextAttributes:attributes forState:UIControlStateDisabled];
}
}
- (void)setNavBarTintColor:(UIColor *)navBarTintColor {
_navBarTintColor = navBarTintColor;
if (navBarTintColor) {
[QMUIHelper visibleViewController].navigationController.navigationBar.tintColor = _navBarTintColor;
}
}
- (void)setNavBarBarTintColor:(UIColor *)navBarBarTintColor {
_navBarBarTintColor = navBarBarTintColor;
if (navBarBarTintColor) {
[UINavigationBar appearance].barTintColor = _navBarBarTintColor;
[QMUIHelper visibleViewController].navigationController.navigationBar.barTintColor = _navBarBarTintColor;
}
}
- (void)setNavBarShadowImage:(UIImage *)navBarShadowImage {
_navBarShadowImage = navBarShadowImage;
if (navBarShadowImage) {
[UINavigationBar appearance].shadowImage = _navBarShadowImage;
[QMUIHelper visibleViewController].navigationController.navigationBar.shadowImage = _navBarShadowImage;
}
}
- (void)setNavBarBackgroundImage:(UIImage *)navBarBackgroundImage {
_navBarBackgroundImage = navBarBackgroundImage;
if (navBarBackgroundImage) {
[[UINavigationBar appearance] setBackgroundImage:_navBarBackgroundImage forBarMetrics:UIBarMetricsDefault];
[[QMUIHelper visibleViewController].navigationController.navigationBar setBackgroundImage:_navBarBackgroundImage forBarMetrics:UIBarMetricsDefault];
}
}
- (void)setNavBarTitleFont:(UIFont *)navBarTitleFont {
_navBarTitleFont = navBarTitleFont;
[self updateNavigationBarTitleAttributesIfNeeded];
}
- (void)setNavBarTitleColor:(UIColor *)navBarTitleColor {
_navBarTitleColor = navBarTitleColor;
[self updateNavigationBarTitleAttributesIfNeeded];
}
- (void)updateNavigationBarTitleAttributesIfNeeded {
if (self.navBarTitleFont || self.navBarTitleColor) {
NSMutableDictionary<NSAttributedStringKey, id> *titleTextAttributes = [UINavigationBar appearance].titleTextAttributes.mutableCopy;
if (!titleTextAttributes) {
titleTextAttributes = [[NSMutableDictionary alloc] init];
}
if (self.navBarTitleFont) {
titleTextAttributes[NSFontAttributeName] = self.navBarTitleFont;
}
if (self.navBarTitleColor) {
titleTextAttributes[NSForegroundColorAttributeName] = self.navBarTitleColor;
}
[UINavigationBar appearance].titleTextAttributes = titleTextAttributes;
[QMUIHelper visibleViewController].navigationController.navigationBar.titleTextAttributes = titleTextAttributes;
}
}
- (void)setNavBarLargeTitleFont:(UIFont *)navBarLargeTitleFont {
_navBarLargeTitleFont = navBarLargeTitleFont;
[self updateNavigationBarLargeTitleTextAttributesIfNeeded];
}
- (void)setNavBarLargeTitleColor:(UIColor *)navBarLargeTitleColor {
_navBarLargeTitleColor = navBarLargeTitleColor;
[self updateNavigationBarLargeTitleTextAttributesIfNeeded];
}
- (void)updateNavigationBarLargeTitleTextAttributesIfNeeded {
if (@available(iOS 11, *)) {
if (self.navBarLargeTitleFont || self.navBarLargeTitleColor) {
NSMutableDictionary<NSString *, id> *largeTitleTextAttributes = [[NSMutableDictionary alloc] init];
if (self.navBarLargeTitleFont) {
largeTitleTextAttributes[NSFontAttributeName] = self.navBarLargeTitleFont;
}
if (self.navBarLargeTitleColor) {
largeTitleTextAttributes[NSForegroundColorAttributeName] = self.navBarLargeTitleColor;
}
[UINavigationBar appearance].largeTitleTextAttributes = largeTitleTextAttributes;
[QMUIHelper visibleViewController].navigationController.navigationBar.largeTitleTextAttributes = largeTitleTextAttributes;
}
}
}
- (void)setSizeNavBarBackIndicatorImageAutomatically:(BOOL)sizeNavBarBackIndicatorImageAutomatically {
_sizeNavBarBackIndicatorImageAutomatically = sizeNavBarBackIndicatorImageAutomatically;
if (sizeNavBarBackIndicatorImageAutomatically && self.navBarBackIndicatorImage && !CGSizeEqualToSize(self.navBarBackIndicatorImage.size, kUINavigationBarBackIndicatorImageSize)) {
self.navBarBackIndicatorImage = self.navBarBackIndicatorImage;// 重新设置一次,以触发自动调整大小
}
}
- (void)setNavBarBackIndicatorImage:(UIImage *)navBarBackIndicatorImage {
_navBarBackIndicatorImage = navBarBackIndicatorImage;
if (_navBarBackIndicatorImage) {
UINavigationBar *navBarAppearance = [UINavigationBar appearance];
UINavigationBar *navigationBar = [QMUIHelper visibleViewController].navigationController.navigationBar;
// 返回按钮的图片frame是和系统默认的返回图片的大小一致的(13, 21),所以用自定义返回箭头时要保证图片大小与系统的箭头大小一样,否则无法对齐
// Make sure custom back button image is the same size as the system's back button image, i.e. (13, 21), due to the same frame size they share.
if (self.sizeNavBarBackIndicatorImageAutomatically) {
CGSize systemBackIndicatorImageSize = kUINavigationBarBackIndicatorImageSize;
CGSize customBackIndicatorImageSize = _navBarBackIndicatorImage.size;
if (!CGSizeEqualToSize(customBackIndicatorImageSize, systemBackIndicatorImageSize)) {
CGFloat imageExtensionVerticalFloat = CGFloatGetCenter(systemBackIndicatorImageSize.height, customBackIndicatorImageSize.height);
_navBarBackIndicatorImage = [[_navBarBackIndicatorImage qmui_imageWithSpacingExtensionInsets:UIEdgeInsetsMake(imageExtensionVerticalFloat,
0,
imageExtensionVerticalFloat,
systemBackIndicatorImageSize.width - customBackIndicatorImageSize.width)] imageWithRenderingMode:_navBarBackIndicatorImage.renderingMode];
}
}
navBarAppearance.backIndicatorImage = _navBarBackIndicatorImage;
navBarAppearance.backIndicatorTransitionMaskImage = _navBarBackIndicatorImage;
navigationBar.backIndicatorImage = _navBarBackIndicatorImage;
navigationBar.backIndicatorTransitionMaskImage = _navBarBackIndicatorImage;
}
}
- (void)setNavBarBackButtonTitlePositionAdjustment:(UIOffset)navBarBackButtonTitlePositionAdjustment {
_navBarBackButtonTitlePositionAdjustment = navBarBackButtonTitlePositionAdjustment;
if (!UIOffsetEqualToOffset(UIOffsetZero, _navBarBackButtonTitlePositionAdjustment)) {
UIBarButtonItem *backBarButtonItem = [UIBarButtonItem appearance];
[backBarButtonItem setBackButtonTitlePositionAdjustment:_navBarBackButtonTitlePositionAdjustment forBarMetrics:UIBarMetricsDefault];
[[QMUIHelper visibleViewController].navigationController.navigationItem.backBarButtonItem setBackButtonTitlePositionAdjustment:_navBarBackButtonTitlePositionAdjustment forBarMetrics:UIBarMetricsDefault];
}
}
- (void)setToolBarTintColor:(UIColor *)toolBarTintColor {
_toolBarTintColor = toolBarTintColor;
if (toolBarTintColor) {
[QMUIHelper visibleViewController].navigationController.toolbar.tintColor = _toolBarTintColor;
}
}
- (void)setToolBarBarTintColor:(UIColor *)toolBarBarTintColor {
_toolBarBarTintColor = toolBarBarTintColor;
if (toolBarBarTintColor) {
[UIToolbar appearance].barTintColor = _toolBarBarTintColor;
[QMUIHelper visibleViewController].navigationController.toolbar.barTintColor = _toolBarBarTintColor;
}
}
- (void)setToolBarBackgroundImage:(UIImage *)toolBarBackgroundImage {
_toolBarBackgroundImage = toolBarBackgroundImage;
if (toolBarBackgroundImage) {
[[UIToolbar appearance] setBackgroundImage:_toolBarBackgroundImage forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[[QMUIHelper visibleViewController].navigationController.toolbar setBackgroundImage:_toolBarBackgroundImage forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
}
}
- (void)setToolBarShadowImageColor:(UIColor *)toolBarShadowImageColor {
_toolBarShadowImageColor = toolBarShadowImageColor;
if (_toolBarShadowImageColor) {
UIImage *shadowImage = [UIImage qmui_imageWithColor:_toolBarShadowImageColor size:CGSizeMake(1, PixelOne) cornerRadius:0];
[[UIToolbar appearance] setShadowImage:shadowImage forToolbarPosition:UIBarPositionAny];
[[QMUIHelper visibleViewController].navigationController.toolbar setShadowImage:shadowImage forToolbarPosition:UIBarPositionAny];
}
}
- (void)setTabBarTintColor:(UIColor *)tabBarTintColor {
_tabBarTintColor = tabBarTintColor;
if (tabBarTintColor) {
[QMUIHelper visibleViewController].tabBarController.tabBar.tintColor = _tabBarTintColor;
}
}
- (void)setTabBarBarTintColor:(UIColor *)tabBarBarTintColor {
_tabBarBarTintColor = tabBarBarTintColor;
if (tabBarBarTintColor) {
[UITabBar appearance].barTintColor = _tabBarBarTintColor;
[QMUIHelper visibleViewController].tabBarController.tabBar.barTintColor = _tabBarBarTintColor;
}
}
- (void)setTabBarBackgroundImage:(UIImage *)tabBarBackgroundImage {
_tabBarBackgroundImage = tabBarBackgroundImage;
if (tabBarBackgroundImage) {
[UITabBar appearance].backgroundImage = _tabBarBackgroundImage;
[QMUIHelper visibleViewController].tabBarController.tabBar.backgroundImage = _tabBarBackgroundImage;
}
}
- (void)setTabBarShadowImageColor:(UIColor *)tabBarShadowImageColor {
_tabBarShadowImageColor = tabBarShadowImageColor;
if (_tabBarShadowImageColor) {
UIImage *shadowImage = [UIImage qmui_imageWithColor:_tabBarShadowImageColor size:CGSizeMake(1, PixelOne) cornerRadius:0];
[[UITabBar appearance] setShadowImage:shadowImage];
[QMUIHelper visibleViewController].tabBarController.tabBar.shadowImage = shadowImage;
}
}
- (void)setTabBarItemTitleColor:(UIColor *)tabBarItemTitleColor {
_tabBarItemTitleColor = tabBarItemTitleColor;
if (_tabBarItemTitleColor) {
NSMutableDictionary<NSString *, id> *textAttributes = [[NSMutableDictionary alloc] initWithDictionary:[[UITabBarItem appearance] titleTextAttributesForState:UIControlStateNormal]];
textAttributes[NSForegroundColorAttributeName] = _tabBarItemTitleColor;
[[UITabBarItem appearance] setTitleTextAttributes:textAttributes forState:UIControlStateNormal];
[[QMUIHelper visibleViewController].tabBarController.tabBar.items enumerateObjectsUsingBlock:^(UITabBarItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[obj setTitleTextAttributes:textAttributes forState:UIControlStateNormal];
}];
}
}
- (void)setTabBarItemTitleFont:(UIFont *)tabBarItemTitleFont {
_tabBarItemTitleFont = tabBarItemTitleFont;
if (_tabBarItemTitleFont) {
NSMutableDictionary<NSString *, id> *textAttributes = [[NSMutableDictionary alloc] initWithDictionary:[[UITabBarItem appearance] titleTextAttributesForState:UIControlStateNormal]];
textAttributes[NSFontAttributeName] = _tabBarItemTitleFont;
[[UITabBarItem appearance] setTitleTextAttributes:textAttributes forState:UIControlStateNormal];
[[QMUIHelper visibleViewController].tabBarController.tabBar.items enumerateObjectsUsingBlock:^(UITabBarItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[obj setTitleTextAttributes:textAttributes forState:UIControlStateNormal];
}];
}
}
- (void)setTabBarItemTitleColorSelected:(UIColor *)tabBarItemTitleColorSelected {
_tabBarItemTitleColorSelected = tabBarItemTitleColorSelected;
if (_tabBarItemTitleColorSelected) {
NSMutableDictionary<NSString *, id> *textAttributes = [[NSMutableDictionary alloc] initWithDictionary:[[UITabBarItem appearance] titleTextAttributesForState:UIControlStateSelected]];
textAttributes[NSForegroundColorAttributeName] = _tabBarItemTitleColorSelected;
[[UITabBarItem appearance] setTitleTextAttributes:textAttributes forState:UIControlStateSelected];
[[QMUIHelper visibleViewController].tabBarController.tabBar.items enumerateObjectsUsingBlock:^(UITabBarItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[obj setTitleTextAttributes:textAttributes forState:UIControlStateSelected];
}];
}
}
@end