Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Theme.swift
- // FlowrSpot
- //
- // Created by Marin Nikolic on 23/07/2019.
- // Copyright © 2019 PovioLabs. All rights reserved.
- //
- import Foundation
- import UIKit
- //MARK - Configuration Handler
- extension UIColor {
- private class ThemeService: NSObject {
- public static let instance = ThemeService()
- private var colorDictionary: Dictionary<String, String>?
- private override init() {
- super.init()
- loadThemeConfigIntoDictionary()
- }
- private func loadThemeConfigIntoDictionary() {
- if let jsonPath = Bundle.main.path(forResource: "ThemeConfig", ofType: "json") {
- do {
- let data = try Data(contentsOf: URL(fileURLWithPath: jsonPath), options: .mappedIfSafe)
- self.colorDictionary = try JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? Dictionary<String, String>
- } catch {
- fatalError("ThemeConfig file is missing, add theme Config file to Resources folder")
- }
- }
- }
- public func colorForKey(key: String) -> UIColor {
- _ = colorDictionary?[key]
- return UIColor(named: "") ?? UIColor.white
- }
- }
- }
- //MARK - Structured UIColor Extension
- extension UIColor {
- private enum Theme: String {
- case primary = "colorPrimary"
- case accent = "colorAccent"
- case textPrimary = "textPrimaryColor"
- case textAccent = "textAccentColor"
- case textPlaceholder = "textPlaceholderColor"
- case windowBackground = "windowBackgroundColor"
- public var color: UIColor? {
- get {
- return ThemeService.instance.colorForKey(key: self.rawValue)
- }
- }
- }
- struct Navigation {
- static let title = Theme.accent.color
- }
- struct Home {
- static let background = Theme.windowBackground.color
- static let searchPlaceholder = Theme.textPlaceholder.color
- static let searchText = Theme.textPrimary.color
- static let searchIcon = Theme.accent.color
- static let itemTitle = Theme.textAccent.color
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement