jsdw_ios/QuickLocation/Manager/Theme/ThemeManager.swift

123 lines
3.9 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// ThemeManager.swift
// SHECommunity
//
// Created by on 2024/11/28.
//
import UIKit
import SwiftyUserDefaults
import ObjectMapper
extension DefaultsKeys {
var themeColor: DefaultsKey<Data?> { .init("ThemeColor") }
var themeFont: DefaultsKey<Data?> { .init("ThemeFont") }
}
public class ThemeManager: NSObject {
public static let shared = ThemeManager()
private var themeColor = ThemeColor()
private var themeFont = ThemeFont()
public var color: ThemeColor {
guard let jsonData = Defaults[\.themeColor] else { return themeColor }
guard let themeColor = ThemeColor(data: jsonData) else { return self.themeColor }
self.themeColor = themeColor
return themeColor
}
public var font: ThemeFont {
guard let jsonData = Defaults[\.themeFont] else { return themeFont }
guard let themeFont = ThemeFont(data: jsonData) else { return self.themeFont }
self.themeFont = themeFont
return themeFont
}
///
public func configure(themeColor: ThemeColor?=nil, themeFont: ThemeFont?=nil) {
if let color = themeColor {
self.themeColor = color
}
if let font = themeFont {
self.themeFont = font
}
}
}
public struct ThemeColor: Mappable {
///
public var mainColor = UIColor(hexStr: "#7AD6FF")
///
public var auxColor = UIColor(hexStr: "#F9BC0C")
///
public var navBarTitleColor = UIColor(hexStr: "#333333")
///
public var titleColor = UIColor(hexStr: "#1F1613")
public var titleAuxColor = UIColor(hexStr: "#333333")
///
public var subTitleColor = UIColor(hexStr: "#666666")
/// #999999
public var contentColor = UIColor(hexStr: "#999999")
/// 线
public var lineColor = UIColor(hexStr: "#F2F2F2")
///
public var backgroundColor = UIColor(hexStr: "#F2F2F2")
///
public var itemBackgroundColor = UIColor(hexStr: "#FFFFFF")
///
public var textBackgroundColor = UIColor(hexStr: "#22A356")
/// disabled线
public var buttonDisabledColor = UIColor(hexStr: "#E6E6E6")
///
public var propertyMainColor = UIColor(hexStr: "#2B67FF")
public init() {
}
public init?(map: Map) {
}
public mutating func mapping(map: Map) {
mainColor <- map["mainColor"]
auxColor <- map["auxColor"]
titleColor <- map["titleColor"]
titleAuxColor <- map["titleAuxColor"]
subTitleColor <- map["subTitleColor"]
contentColor <- map["contentColor"]
lineColor <- map["lineColor"]
backgroundColor <- map["backgroundColor"]
itemBackgroundColor <- map["itemBackgroundColor"]
textBackgroundColor <- map["textBackgroundColor"]
buttonDisabledColor <- map["buttonDisabledColor"]
}
}
public struct ThemeFont: Mappable {
///
public var navBarFont = UIFont.systemFont(ofSize: 18, weight: .bold)
///
public var titleFont = UIFont.systemFont(ofSize: 16, weight: .bold)
///
public var contentFont = UIFont.systemFont(ofSize: 12, weight: .regular)
public var subContentFont = UIFont.systemFont(ofSize: 10, weight: .regular)
public init() {
}
public init?(map: Map) {
}
public mutating func mapping(map: Map) {
navBarFont <- map["navBarFont"]
titleFont <- map["titleFont"]
contentFont <- map["contentFont"]
subContentFont <- map["subContentFont"]
}
}