react-native-navigation的迁移库

UINavigationBar+utils.m 3.0KB

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