ThemeManager.swift 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. //
  2. // ThemeManager.swift
  3. // DragonflySchool
  4. //
  5. // Created by virgil on 16/1/5.
  6. // Copyright © 2016年 virgil. All rights reserved.
  7. //
  8. import UIKit
  9. var themeKey = "AOBJ_THEME"
  10. let notification_theme = "notification_theme"
  11. class ThemeManager: NSObject {
  12. var themeName: String!
  13. var themePath: String!
  14. var themeColor: String!
  15. var themePaths = ["default": "default", "night": "night", "yellow": "yellow"]
  16. //菜单栏右侧发布
  17. var themeFontRightOpen = ["default": UIColor.white, "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x566384, alpha: 1), "yellow": CommonUntils.getUIColorFromRGB(rgbValue: 0x000000, alpha: 1)]
  18. // MARK: =======================================输入框部分=======================================
  19. //输入框border颜色 默认灰色夜间深色
  20. var themFieldBorderColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xd6d7dc, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x282f3f, alpha: 1), "yellow": UIColor.yellow]
  21. //输入框字体颜色
  22. var themFieldFontColor = ["default": UIColor.black, "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x535f7f, alpha: 1), "yellow": UIColor.yellow]
  23. //输入框背景颜色
  24. var themFieldBackgroundColor = ["default": UIColor.white, "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x566384, alpha: 1), "yellow": UIColor.yellow]
  25. //输入框placeholder字体颜色
  26. var themFieldPlaceholderFontColor = ["default": UIColor.gray, "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x535f7f, alpha: 1), "yellow": UIColor.yellow]
  27. // MARK: =======================================按钮部分=======================================
  28. //黄色按钮背景颜色
  29. var themeOrangeButtonBackgroudColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xFF5F3E, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0xa4aabb, alpha: 1), "yellow": UIColor.yellow]
  30. //黄色按钮字体颜色
  31. var themeOrangeButtonFontColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xffffff, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0xa4aabb, alpha: 1), "yellow": UIColor.yellow]
  32. // MARK: =======================================导航菜单=======================================
  33. //导航栏背景颜色
  34. var themeNavBackgroudColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0x16B7F5, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x343c4e, alpha: 1), "yellow": UIColor.yellow]
  35. //导航栏标题字体颜色
  36. var themeNavTitleColor = ["default": UIColor.white, "night": CommonUntils.getUIColorFromRGB(rgbValue: 0xa4aabb, alpha: 1), "yellow": UIColor.yellow]
  37. // MARK: =======================================公用部分=======================================
  38. var themeBackgroudColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xf5f5f9, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x343c4e, alpha: 1), "yellow": UIColor.yellow]
  39. //Cell背景颜色
  40. var themeCellBackgroudColor = ["default": UIColor.white, "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x384155, alpha: 1), "yellow": UIColor.yellow]
  41. //分割线颜色
  42. var themeLineBlackColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xdbd6d6, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x3f495f, alpha: 1), "yellow": UIColor.yellow]
  43. // MARK: =======================================字体颜色部分部分=======================================
  44. //标题字体颜色
  45. var themeFontBlackColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0x323232, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x8791aa, alpha: 1), "yellow": UIColor.yellow]
  46. //二级标题字体颜色
  47. var themeFontGrayColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xb4b4b4, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x566384, alpha: 1), "yellow": UIColor.yellow]
  48. //三级标题字体颜色
  49. var themeFontLightGrayColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xb4b4b4, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x566384, alpha: 1), "yellow": UIColor.lightGray]
  50. //黄色字体颜色
  51. var themeFontOrangeColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xff5f3e, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x566384, alpha: 1), "yellow": UIColor.lightGray]
  52. // MARK: =======================================选择菜单=======================================
  53. //背景颜色 未选中
  54. var themTabBackgroudColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xffffff, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x343c4e, alpha:
  55. 1), "yellow": UIColor.yellow]
  56. //背景颜色 选中
  57. var themTabSelectedBackgroudColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xf38711, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x596785, alpha:
  58. 1), "yellow": UIColor.yellow]
  59. //字体颜色 未选中
  60. var themTabFontColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xf38711, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x4a546d, alpha:
  61. 1), "yellow": UIColor.yellow]
  62. //字体颜色 选中
  63. var themTabSelectedFontColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xffffff, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0xa4aabb, alpha:
  64. 1), "yellow": UIColor.yellow]
  65. //边框颜色
  66. var themTabBorderColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xf38711, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x596785, alpha:
  67. 1), "yellow": UIColor.yellow]
  68. // MARK: =======================================tabbar字体颜色=======================================
  69. //tabbar默认字体颜色
  70. var themeTabbarDefaultFontColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0x6A6A69, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x6A6A69, alpha: 1), "yellow": UIColor.yellow]
  71. //导航栏标题字体颜色
  72. var themeTabbarSelectedFontColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0x16B7F5, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0xa4aabb, alpha: 1), "yellow": UIColor.yellow]
  73. // MARK: =======================================实现方法=======================================
  74. /**
  75. Tabbar默认字体颜色背景颜色 未选中
  76. :returns: <#return value description#>
  77. */
  78. func getTabbarDefaultFontColor() -> UIColor {
  79. return self.themeTabbarDefaultFontColor[self.themeName]!
  80. }
  81. /**
  82. Tabbar 选中字体颜色
  83. :returns: <#return value description#>
  84. */
  85. func getTabbarSelectedFontColor() -> UIColor {
  86. return self.themeTabbarSelectedFontColor[self.themeName]!
  87. }
  88. /**
  89. 分割线颜色
  90. :returns: <#return value description#>
  91. */
  92. func getLineBackColor() -> UIColor {
  93. return self.themeLineBlackColor[self.themeName]!
  94. }
  95. /**
  96. 标题字体的颜色值
  97. :returns: <#return value description#>
  98. */
  99. func getFontBlackColor() -> UIColor {
  100. return self.themeFontBlackColor[self.themeName]!
  101. }
  102. /**
  103. 二级标题字体的颜色值
  104. :returns: <#return value description#>
  105. */
  106. func getFontGrayColor() -> UIColor {
  107. return self.themeFontGrayColor[self.themeName]!
  108. }
  109. /**
  110. 三级标题字体的颜色值
  111. :returns: <#return value description#>
  112. */
  113. func getFontLightGrayColor() -> UIColor {
  114. return self.themeFontLightGrayColor[self.themeName]!
  115. }
  116. /**
  117. 黄色字体的颜色值
  118. :returns: <#return value description#>
  119. */
  120. func getFontOrangeColor() -> UIColor {
  121. return self.themeFontOrangeColor[self.themeName]!
  122. }
  123. /**
  124. CEll 背景颜色
  125. :returns: <#return value description#>
  126. */
  127. func getCellBackgroudColor() -> UIColor {
  128. return self.themeCellBackgroudColor[self.themeName]!
  129. }
  130. /**
  131. 输入框背景颜色
  132. :returns: <#return value description#>
  133. */
  134. func getFieldBackgroundColor() -> UIColor {
  135. return self.themFieldBackgroundColor[self.themeName]!
  136. }
  137. /**
  138. 输入框border颜色
  139. :returns: <#return value description#>
  140. */
  141. func getFieldBorderBackgroudColor() -> UIColor {
  142. return self.themFieldBorderColor[self.themeName]!
  143. }
  144. /**
  145. 输入框placeholder字体颜色
  146. :returns: <#return value description#>
  147. */
  148. func getFieldPlaceholderFontColor() -> UIColor {
  149. return self.themFieldPlaceholderFontColor[self.themeName]!
  150. }
  151. /**
  152. 输入框字体颜色
  153. :returns: <#return value description#>
  154. */
  155. func getFieldFontColor() -> UIColor {
  156. return self.themFieldFontColor[self.themeName]!
  157. }
  158. /**
  159. 黄色按钮字体颜色
  160. :returns: <#return value description#>
  161. */
  162. func getOrangeButtonFontColor() -> UIColor {
  163. return self.themeOrangeButtonFontColor[self.themeName]!
  164. }
  165. /**
  166. 黄色按钮背景颜色
  167. :returns: <#return value description#>
  168. */
  169. func getOrangeButtonBackgroudColor() -> UIColor {
  170. return self.themeOrangeButtonBackgroudColor[self.themeName]!
  171. }
  172. /**
  173. 公用背景颜色
  174. :returns: <#return value description#>
  175. */
  176. func getBackgroudColor() -> UIColor {
  177. return self.themeBackgroudColor[self.themeName]!
  178. }
  179. /**
  180. 导航栏背景颜色
  181. :returns: <#return value description#>
  182. */
  183. func getNavBackgroudColor() -> UIColor {
  184. return self.themeNavBackgroudColor[self.themeName]!
  185. }
  186. /**
  187. 导航栏标题字体颜色
  188. :returns: <#return value description#>
  189. */
  190. func getNavTitleColor() -> UIColor {
  191. return self.themeNavTitleColor[self.themeName]!
  192. }
  193. /**
  194. 背景颜色 未选中
  195. :returns: <#return value description#>
  196. */
  197. func getTabBackgroudColor() -> UIColor {
  198. return self.themTabBackgroudColor[self.themeName]!
  199. }
  200. /**
  201. 背景颜色 选中
  202. :returns: <#return value description#>
  203. */
  204. func getTabSelectedBackgroudColor() -> UIColor {
  205. return self.themTabSelectedBackgroudColor[self.themeName]!
  206. }
  207. /**
  208. 字体颜色 未选中
  209. :returns: <#return value description#>
  210. */
  211. func getTabFontColor() -> UIColor {
  212. return self.themTabFontColor[self.themeName]!
  213. }
  214. /**
  215. 字体颜色 选中
  216. :returns: <#return value description#>
  217. */
  218. func getTabSelectedFontColor() -> UIColor {
  219. return self.themTabSelectedFontColor[self.themeName]!
  220. }
  221. /**
  222. 边框颜色
  223. :returns: <#return value description#>
  224. */
  225. func getTabBorderColor() -> UIColor {
  226. return self.themTabBorderColor[self.themeName]!
  227. }
  228. /**
  229. 导航菜单右侧发布按钮字体颜色
  230. :returns: <#return value description#>
  231. */
  232. func getFontRightOpenColor() -> UIColor {
  233. return self.themeFontRightOpen[self.themeName]!
  234. }
  235. static var _themeManager: ThemeManager?
  236. class func sharedInstance() -> ThemeManager! {
  237. themeKey = "AOBJ_THEME"
  238. if _themeManager==nil {
  239. _themeManager = ThemeManager()
  240. if UserDefault.object(forKey: themeKey)==nil {
  241. _themeManager?.themeName = "default"
  242. } else {
  243. print(UserDefault.object(forKey: themeKey) as! String)
  244. _themeManager?.themeName = UserDefault.object(forKey: themeKey) as! String
  245. }
  246. // _themeManager?.themeName = "default"
  247. print(_themeManager?.themeName )
  248. UserDefault.setValue(_themeManager?.themeName, forKey: themeKey)
  249. _themeManager?.themePath = _themeManager?.themePaths[_themeManager!.themeName]
  250. }
  251. return _themeManager
  252. }
  253. /**
  254. 切换皮肤
  255. :param: themeName themeName description
  256. :returns: 1111111111
  257. */
  258. func changeTheme(themeName: String!) {
  259. if themeName == "" {
  260. return
  261. }
  262. UserDefault.setValue(themeName, forKey: themeKey)
  263. self.themeName = themeName
  264. self.themePath = self.themePaths[self.themeName]
  265. }
  266. /**
  267. 获取皮肤中的图片
  268. :param: imgName <#imgName description#>
  269. :returns: <#return value description#>
  270. */
  271. func themedImageWithName(imgName: String!) -> UIImage? {
  272. if imgName == "" {
  273. return nil
  274. }
  275. return UIImage(named: imgName)
  276. }
  277. }