BaseNaviController.m
2.2 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
//
// BaseNaviController.m
// DreamSleep
//
// Created by peter on 2022/4/9.
//
#import "BaseNaviController.h"
@interface BaseNaviController ()
@end
@implementation BaseNaviController
- (void)viewDidLoad {
[super viewDidLoad];
// 设置导航栏返回按钮颜色
self.navigationBar.tintColor = DSWhite;
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (self.childViewControllers.count == 1) {
viewController.hidesBottomBarWhenPushed = YES;
} else {
viewController.hidesBottomBarWhenPushed = NO;
}
[super pushViewController:viewController animated:animated];
}
+ (void)setNavigationBarStyle:(NaviStyle)style vc:(UIViewController *)vc {
UINavigationBar *naviBar = vc.navigationController.navigationBar;
// NaviStyleDefault
UIColor *titleColor = DSWhite;
UIColor *bgColor = BrandColor;
UIColor *barTintColor = BrandColor;
if (style == NaviStyleLight) {
titleColor = ColorFromHex(0x333333);
bgColor = DSWhite;
barTintColor = DSWhite;
} else if (style == NaviStyleDark) {
titleColor = DSWhite;
bgColor = DarkColor;
barTintColor = DarkColor;
}
// 设置导航栏title颜色、导航栏背景色、隐藏分割线
NSDictionary *titleTextAttributes = @{NSForegroundColorAttributeName:titleColor};
if (@available(iOS 13.0, *)) {
UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
// 导航栏title颜色
appearance.titleTextAttributes = titleTextAttributes;
// 导航栏背景色
appearance.backgroundColor = bgColor;
// 隐藏分割线
appearance.shadowColor = DSClearColor;
// 生效
naviBar.scrollEdgeAppearance = appearance;
// 滚动视图滚动后导航栏背景色不会被影响
naviBar.standardAppearance = appearance;
} else {
// 导航栏title颜色
[naviBar setTitleTextAttributes:titleTextAttributes];
// 导航栏背景色
naviBar.barTintColor = barTintColor;
naviBar.translucent = NO;
// 隐藏分割线
naviBar.shadowImage = [UIImage new];
}
}
@end