// // ThemeManager.swift // DragonflySchool // // Created by virgil on 16/1/5. // Copyright © 2016年 virgil. All rights reserved. // import UIKit var themeKey = "AOBJ_THEME" let notification_theme = "notification_theme" class ThemeManager: NSObject { var themeName: String! var themePath: String! var themeColor: String! var themePaths = ["default": "default", "night": "night", "yellow": "yellow"] //菜单栏右侧发布 var themeFontRightOpen = ["default": UIColor.white, "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x566384, alpha: 1), "yellow": CommonUntils.getUIColorFromRGB(rgbValue: 0x000000, alpha: 1)] // MARK: =======================================输入框部分======================================= //输入框border颜色 默认灰色夜间深色 var themFieldBorderColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xd6d7dc, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x282f3f, alpha: 1), "yellow": UIColor.yellow] //输入框字体颜色 var themFieldFontColor = ["default": UIColor.black, "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x535f7f, alpha: 1), "yellow": UIColor.yellow] //输入框背景颜色 var themFieldBackgroundColor = ["default": UIColor.white, "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x566384, alpha: 1), "yellow": UIColor.yellow] //输入框placeholder字体颜色 var themFieldPlaceholderFontColor = ["default": UIColor.gray, "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x535f7f, alpha: 1), "yellow": UIColor.yellow] // MARK: =======================================按钮部分======================================= //黄色按钮背景颜色 var themeOrangeButtonBackgroudColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xFF5F3E, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0xa4aabb, alpha: 1), "yellow": UIColor.yellow] //黄色按钮字体颜色 var themeOrangeButtonFontColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xffffff, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0xa4aabb, alpha: 1), "yellow": UIColor.yellow] // MARK: =======================================导航菜单======================================= //导航栏背景颜色 var themeNavBackgroudColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0x16B7F5, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x343c4e, alpha: 1), "yellow": UIColor.yellow] //导航栏标题字体颜色 var themeNavTitleColor = ["default": UIColor.white, "night": CommonUntils.getUIColorFromRGB(rgbValue: 0xa4aabb, alpha: 1), "yellow": UIColor.yellow] // MARK: =======================================公用部分======================================= var themeBackgroudColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xf5f5f9, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x343c4e, alpha: 1), "yellow": UIColor.yellow] //Cell背景颜色 var themeCellBackgroudColor = ["default": UIColor.white, "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x384155, alpha: 1), "yellow": UIColor.yellow] //分割线颜色 var themeLineBlackColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xdbd6d6, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x3f495f, alpha: 1), "yellow": UIColor.yellow] // MARK: =======================================字体颜色部分部分======================================= //标题字体颜色 var themeFontBlackColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0x323232, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x8791aa, alpha: 1), "yellow": UIColor.yellow] //二级标题字体颜色 var themeFontGrayColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xb4b4b4, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x566384, alpha: 1), "yellow": UIColor.yellow] //三级标题字体颜色 var themeFontLightGrayColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xb4b4b4, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x566384, alpha: 1), "yellow": UIColor.lightGray] //黄色字体颜色 var themeFontOrangeColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xff5f3e, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x566384, alpha: 1), "yellow": UIColor.lightGray] // MARK: =======================================选择菜单======================================= //背景颜色 未选中 var themTabBackgroudColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xffffff, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x343c4e, alpha: 1), "yellow": UIColor.yellow] //背景颜色 选中 var themTabSelectedBackgroudColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xf38711, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x596785, alpha: 1), "yellow": UIColor.yellow] //字体颜色 未选中 var themTabFontColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xf38711, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x4a546d, alpha: 1), "yellow": UIColor.yellow] //字体颜色 选中 var themTabSelectedFontColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xffffff, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0xa4aabb, alpha: 1), "yellow": UIColor.yellow] //边框颜色 var themTabBorderColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0xf38711, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x596785, alpha: 1), "yellow": UIColor.yellow] // MARK: =======================================tabbar字体颜色======================================= //tabbar默认字体颜色 var themeTabbarDefaultFontColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0x6A6A69, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0x6A6A69, alpha: 1), "yellow": UIColor.yellow] //导航栏标题字体颜色 var themeTabbarSelectedFontColor = ["default": CommonUntils.getUIColorFromRGB(rgbValue: 0x16B7F5, alpha: 1), "night": CommonUntils.getUIColorFromRGB(rgbValue: 0xa4aabb, alpha: 1), "yellow": UIColor.yellow] // MARK: =======================================实现方法======================================= /** Tabbar默认字体颜色背景颜色 未选中 :returns: <#return value description#> */ func getTabbarDefaultFontColor() -> UIColor { return self.themeTabbarDefaultFontColor[self.themeName]! } /** Tabbar 选中字体颜色 :returns: <#return value description#> */ func getTabbarSelectedFontColor() -> UIColor { return self.themeTabbarSelectedFontColor[self.themeName]! } /** 分割线颜色 :returns: <#return value description#> */ func getLineBackColor() -> UIColor { return self.themeLineBlackColor[self.themeName]! } /** 标题字体的颜色值 :returns: <#return value description#> */ func getFontBlackColor() -> UIColor { return self.themeFontBlackColor[self.themeName]! } /** 二级标题字体的颜色值 :returns: <#return value description#> */ func getFontGrayColor() -> UIColor { return self.themeFontGrayColor[self.themeName]! } /** 三级标题字体的颜色值 :returns: <#return value description#> */ func getFontLightGrayColor() -> UIColor { return self.themeFontLightGrayColor[self.themeName]! } /** 黄色字体的颜色值 :returns: <#return value description#> */ func getFontOrangeColor() -> UIColor { return self.themeFontOrangeColor[self.themeName]! } /** CEll 背景颜色 :returns: <#return value description#> */ func getCellBackgroudColor() -> UIColor { return self.themeCellBackgroudColor[self.themeName]! } /** 输入框背景颜色 :returns: <#return value description#> */ func getFieldBackgroundColor() -> UIColor { return self.themFieldBackgroundColor[self.themeName]! } /** 输入框border颜色 :returns: <#return value description#> */ func getFieldBorderBackgroudColor() -> UIColor { return self.themFieldBorderColor[self.themeName]! } /** 输入框placeholder字体颜色 :returns: <#return value description#> */ func getFieldPlaceholderFontColor() -> UIColor { return self.themFieldPlaceholderFontColor[self.themeName]! } /** 输入框字体颜色 :returns: <#return value description#> */ func getFieldFontColor() -> UIColor { return self.themFieldFontColor[self.themeName]! } /** 黄色按钮字体颜色 :returns: <#return value description#> */ func getOrangeButtonFontColor() -> UIColor { return self.themeOrangeButtonFontColor[self.themeName]! } /** 黄色按钮背景颜色 :returns: <#return value description#> */ func getOrangeButtonBackgroudColor() -> UIColor { return self.themeOrangeButtonBackgroudColor[self.themeName]! } /** 公用背景颜色 :returns: <#return value description#> */ func getBackgroudColor() -> UIColor { return self.themeBackgroudColor[self.themeName]! } /** 导航栏背景颜色 :returns: <#return value description#> */ func getNavBackgroudColor() -> UIColor { return self.themeNavBackgroudColor[self.themeName]! } /** 导航栏标题字体颜色 :returns: <#return value description#> */ func getNavTitleColor() -> UIColor { return self.themeNavTitleColor[self.themeName]! } /** 背景颜色 未选中 :returns: <#return value description#> */ func getTabBackgroudColor() -> UIColor { return self.themTabBackgroudColor[self.themeName]! } /** 背景颜色 选中 :returns: <#return value description#> */ func getTabSelectedBackgroudColor() -> UIColor { return self.themTabSelectedBackgroudColor[self.themeName]! } /** 字体颜色 未选中 :returns: <#return value description#> */ func getTabFontColor() -> UIColor { return self.themTabFontColor[self.themeName]! } /** 字体颜色 选中 :returns: <#return value description#> */ func getTabSelectedFontColor() -> UIColor { return self.themTabSelectedFontColor[self.themeName]! } /** 边框颜色 :returns: <#return value description#> */ func getTabBorderColor() -> UIColor { return self.themTabBorderColor[self.themeName]! } /** 导航菜单右侧发布按钮字体颜色 :returns: <#return value description#> */ func getFontRightOpenColor() -> UIColor { return self.themeFontRightOpen[self.themeName]! } static var _themeManager: ThemeManager? class func sharedInstance() -> ThemeManager! { themeKey = "AOBJ_THEME" if _themeManager==nil { _themeManager = ThemeManager() if UserDefault.object(forKey: themeKey)==nil { _themeManager?.themeName = "default" } else { print(UserDefault.object(forKey: themeKey) as! String) _themeManager?.themeName = UserDefault.object(forKey: themeKey) as! String } // _themeManager?.themeName = "default" print(_themeManager?.themeName ) UserDefault.setValue(_themeManager?.themeName, forKey: themeKey) _themeManager?.themePath = _themeManager?.themePaths[_themeManager!.themeName] } return _themeManager } /** 切换皮肤 :param: themeName themeName description :returns: 1111111111 */ func changeTheme(themeName: String!) { if themeName == "" { return } UserDefault.setValue(themeName, forKey: themeKey) self.themeName = themeName self.themePath = self.themePaths[self.themeName] } /** 获取皮肤中的图片 :param: imgName <#imgName description#> :returns: <#return value description#> */ func themedImageWithName(imgName: String!) -> UIImage? { if imgName == "" { return nil } return UIImage(named: imgName) } }