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