ThemeFontPicker.swift 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. //
  2. // ThemeFontPicker.swift
  3. // SwiftTheme
  4. //
  5. // Created by Gesen on 2017/1/28.
  6. // Copyright © 2017年 Gesen. All rights reserved.
  7. //
  8. import UIKit
  9. @objc public final class ThemeFontPicker: ThemePicker {
  10. public convenience init(keyPath: String, map: @escaping (Any?) -> UIFont?) {
  11. self.init(v: { map(O2ThemeManager.value(for: keyPath)) })
  12. }
  13. public convenience init(fonts: UIFont...) {
  14. self.init(v: { O2ThemeManager.element(for: fonts) })
  15. }
  16. public required convenience init(arrayLiteral elements: UIFont...) {
  17. self.init(v: { O2ThemeManager.element(for: elements) })
  18. }
  19. }
  20. @objc public extension ThemeFontPicker {
  21. class func pickerWithKeyPath(_ keyPath: String, map: @escaping (Any?) -> UIFont?) -> ThemeFontPicker {
  22. return ThemeFontPicker(v: { map(O2ThemeManager.value(for: keyPath)) })
  23. }
  24. class func pickerWithFonts(_ fonts: [UIFont]) -> ThemeFontPicker {
  25. return ThemeFontPicker(v: { O2ThemeManager.element(for: fonts) })
  26. }
  27. }
  28. extension ThemeFontPicker: ExpressibleByArrayLiteral {}