|
@@ -0,0 +1,82 @@
|
|
1
|
+#import "UINavigationBar+utils.h"
|
|
2
|
+
|
|
3
|
+const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;
|
|
4
|
+
|
|
5
|
+@implementation UINavigationBar (utils)
|
|
6
|
+
|
|
7
|
+- (void)rnn_setBackgroundColor:(UIColor *)color {
|
|
8
|
+ CGFloat bgColorAlpha = CGColorGetAlpha(color.CGColor);
|
|
9
|
+
|
|
10
|
+ if (color && bgColorAlpha == 0.0) {
|
|
11
|
+ [self rnn_setBackgroundColorTransparent];
|
|
12
|
+ } else {
|
|
13
|
+ [self removeTransparentView];
|
|
14
|
+ if (@available(iOS 13.0, *)) {
|
|
15
|
+ [self getNavigaitonBarStandardAppearance].backgroundColor = color;
|
|
16
|
+ [self getNavigaitonBarCompactAppearance].backgroundColor = color;
|
|
17
|
+ [self getNavigaitonBarScrollEdgeAppearance].backgroundColor = color;
|
|
18
|
+ }
|
|
19
|
+ self.barTintColor = color;
|
|
20
|
+ }
|
|
21
|
+}
|
|
22
|
+
|
|
23
|
+- (void)rnn_setBackgroundColorTransparent {
|
|
24
|
+ if (![self viewWithTag:TOP_BAR_TRANSPARENT_TAG]){
|
|
25
|
+ UIView *transparentView = [[UIView alloc] initWithFrame:CGRectZero];
|
|
26
|
+ transparentView.backgroundColor = [UIColor clearColor];
|
|
27
|
+ transparentView.tag = TOP_BAR_TRANSPARENT_TAG;
|
|
28
|
+ [self insertSubview:transparentView atIndex:0];
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+ self.translucent = YES;
|
|
32
|
+ [self setBackgroundColor:[UIColor clearColor]];
|
|
33
|
+ self.shadowImage = [UIImage new];
|
|
34
|
+ [self setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
|
|
35
|
+ if (@available(iOS 13.0, *)) {
|
|
36
|
+ UINavigationBarAppearance *standardAppearance = [self getNavigaitonBarStandardAppearance];
|
|
37
|
+ standardAppearance.backgroundColor = [UIColor clearColor];
|
|
38
|
+ standardAppearance.shadowImage = [UIImage new];
|
|
39
|
+ standardAppearance.backgroundImage = [UIImage new];
|
|
40
|
+
|
|
41
|
+ UINavigationBarAppearance *compactAppearance = [self getNavigaitonBarCompactAppearance];
|
|
42
|
+ compactAppearance.backgroundColor = [UIColor clearColor];
|
|
43
|
+ compactAppearance.shadowImage = [UIImage new];
|
|
44
|
+ compactAppearance.backgroundImage = [UIImage new];
|
|
45
|
+
|
|
46
|
+ UINavigationBarAppearance *scrollEdgeAppearance = [self getNavigaitonBarScrollEdgeAppearance];
|
|
47
|
+ scrollEdgeAppearance.backgroundColor = [UIColor clearColor];
|
|
48
|
+ scrollEdgeAppearance.shadowImage = [UIImage new];
|
|
49
|
+ scrollEdgeAppearance.backgroundImage = [UIImage new];
|
|
50
|
+ }
|
|
51
|
+}
|
|
52
|
+
|
|
53
|
+- (void)removeTransparentView {
|
|
54
|
+ UIView *transparentView = [self viewWithTag:TOP_BAR_TRANSPARENT_TAG];
|
|
55
|
+ if (transparentView){
|
|
56
|
+ [transparentView removeFromSuperview];
|
|
57
|
+ }
|
|
58
|
+}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+- (UINavigationBarAppearance*)getNavigaitonBarStandardAppearance API_AVAILABLE(ios(13.0)) {
|
|
62
|
+ if (!self.standardAppearance) {
|
|
63
|
+ self.standardAppearance = [UINavigationBarAppearance new];
|
|
64
|
+ }
|
|
65
|
+ return self.standardAppearance;
|
|
66
|
+}
|
|
67
|
+
|
|
68
|
+- (UINavigationBarAppearance*)getNavigaitonBarCompactAppearance API_AVAILABLE(ios(13.0)) {
|
|
69
|
+ if (!self.compactAppearance) {
|
|
70
|
+ self.compactAppearance = [UINavigationBarAppearance new];
|
|
71
|
+ }
|
|
72
|
+ return self.compactAppearance;
|
|
73
|
+}
|
|
74
|
+
|
|
75
|
+- (UINavigationBarAppearance*)getNavigaitonBarScrollEdgeAppearance API_AVAILABLE(ios(13.0)) {
|
|
76
|
+ if (!self.scrollEdgeAppearance) {
|
|
77
|
+ self.scrollEdgeAppearance = [UINavigationBarAppearance new];
|
|
78
|
+ }
|
|
79
|
+ return self.scrollEdgeAppearance;
|
|
80
|
+}
|
|
81
|
+
|
|
82
|
+@end
|