WFCUConfigManager.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. //
  2. // WFCUConfigManager.m
  3. // WFChatUIKit
  4. //
  5. // Created by heavyrain lee on 2019/9/22.
  6. // Copyright © 2019 WF Chat. All rights reserved.
  7. //
  8. #import "WFCUConfigManager.h"
  9. #import "UIColor+YH.h"
  10. static WFCUConfigManager *sharedSingleton = nil;
  11. @implementation WFCUConfigManager
  12. + (WFCUConfigManager *)globalManager {
  13. if (sharedSingleton == nil) {
  14. @synchronized (self) {
  15. if (sharedSingleton == nil) {
  16. sharedSingleton = [[WFCUConfigManager alloc] init];
  17. }
  18. }
  19. }
  20. return sharedSingleton;
  21. }
  22. - (instancetype)init {
  23. self = [super init];
  24. if (self) {
  25. _themeType = [[NSUserDefaults standardUserDefaults] integerForKey:@"WFC_THEME_TYPE"];
  26. }
  27. return self;
  28. }
  29. -(void)setThemeType:(WFCUThemeType)themeType {
  30. _themeType = themeType;
  31. [[NSUserDefaults standardUserDefaults] setInteger:themeType forKey:@"WFC_THEME_TYPE"];
  32. [[NSUserDefaults standardUserDefaults] synchronize];
  33. [self setupNavBar];
  34. }
  35. - (void)setupNavBar {
  36. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  37. UINavigationBar *bar = [UINavigationBar appearance];
  38. bar.barTintColor = [WFCUConfigManager globalManager].naviBackgroudColor;
  39. bar.tintColor = [WFCUConfigManager globalManager].naviTextColor;
  40. bar.titleTextAttributes = @{NSForegroundColorAttributeName : [WFCUConfigManager globalManager].naviTextColor};
  41. bar.barStyle = UIBarStyleDefault;
  42. if (@available(iOS 13, *)) {
  43. UINavigationBarAppearance *navBarAppearance = [[UINavigationBarAppearance alloc] init];
  44. bar.standardAppearance = navBarAppearance;
  45. bar.scrollEdgeAppearance = navBarAppearance;
  46. navBarAppearance.backgroundColor = [WFCUConfigManager globalManager].naviBackgroudColor;
  47. navBarAppearance.titleTextAttributes = @{NSForegroundColorAttributeName:[WFCUConfigManager globalManager].naviTextColor};
  48. }
  49. [[UITabBar appearance] setBarTintColor:[WFCUConfigManager globalManager].frameBackgroudColor];
  50. [UITabBar appearance].translucent = NO;
  51. }
  52. - (UIColor *)backgroudColor {
  53. if (_backgroudColor) {
  54. return _backgroudColor;
  55. }
  56. BOOL darkModel = NO;
  57. if (@available(iOS 13.0, *)) {
  58. if(UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  59. darkModel = YES;
  60. }
  61. }
  62. if (darkModel) {
  63. return [UIColor colorWithRed:33/255.f green:33/255.f blue:33/255.f alpha:1.0f];
  64. } else {
  65. if (self.themeType == ThemeType_WFChat) {
  66. return [UIColor colorWithRed:243/255.f green:243/255.f blue:243/255.f alpha:1.0f];
  67. } else if (self.themeType == ThemeType_White) {
  68. return [UIColor colorWithHexString:@"0xededed"];
  69. }
  70. return [UIColor whiteColor];
  71. }
  72. }
  73. - (UIColor *)frameBackgroudColor {
  74. if (_frameBackgroudColor) {
  75. return _frameBackgroudColor;
  76. }
  77. BOOL darkModel = NO;
  78. if (@available(iOS 13.0, *)) {
  79. if(UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  80. darkModel = YES;
  81. }
  82. }
  83. if (darkModel) {
  84. return [UIColor colorWithRed:39/255.f green:39/255.f blue:39/255.f alpha:1.0f];
  85. } else {
  86. return [UIColor colorWithRed:239/255.f green:239/255.f blue:239/255.f alpha:1.0f];
  87. }
  88. }
  89. - (UIColor *)textColor {
  90. if (_textColor) {
  91. return _textColor;
  92. }
  93. BOOL darkModel = NO;
  94. if (@available(iOS 13.0, *)) {
  95. if(UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  96. darkModel = YES;
  97. }
  98. }
  99. if (darkModel) {
  100. return [UIColor whiteColor];
  101. } else {
  102. return [UIColor colorWithHexString:@"0x1d1d1d"];
  103. }
  104. }
  105. - (UIColor *)naviBackgroudColor {
  106. if (_naviBackgroudColor) {
  107. return _naviBackgroudColor;
  108. }
  109. BOOL darkModel = NO;
  110. if (@available(iOS 13.0, *)) {
  111. if(UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  112. darkModel = YES;
  113. }
  114. }
  115. if (darkModel) {
  116. return [UIColor colorWithRed:39/255.f green:39/255.f blue:39/255.f alpha:1.0f];
  117. } else {
  118. if (self.themeType == ThemeType_WFChat) {
  119. return [UIColor colorWithRed:0.1 green:0.27 blue:0.9 alpha:0.9];
  120. } else if(self.themeType == ThemeType_White) {
  121. return [UIColor colorWithHexString:@"0xededed"];;
  122. }
  123. return [UIColor colorWithRed:239/255.f green:239/255.f blue:239/255.f alpha:1.0f];
  124. }
  125. }
  126. - (UIColor *)naviTextColor {
  127. if (_naviTextColor) {
  128. return _naviTextColor;
  129. }
  130. BOOL darkModel = NO;
  131. if (@available(iOS 13.0, *)) {
  132. if(UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  133. darkModel = YES;
  134. }
  135. }
  136. if (darkModel) {
  137. return [UIColor whiteColor];
  138. } else {
  139. if (self.themeType == ThemeType_WFChat) {
  140. return [UIColor blackColor];
  141. } else if(self.themeType == ThemeType_White) {
  142. [UIColor colorWithHexString:@"0c0c0c"];
  143. }
  144. return [UIColor blackColor];
  145. }
  146. }
  147. @end