ThemeCGFloatPicker.swift 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // ThemeCGFloatPicker.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 ThemeCGFloatPicker: ThemePicker{
  10. public convenience init(keyPath: String) {
  11. self.init(v: { CGFloat(O2ThemeManager.number(for: keyPath)?.doubleValue ?? 0) })
  12. }
  13. public convenience init(keyPath: String, map: @escaping (Any?) -> CGFloat?) {
  14. self.init(v: { map(O2ThemeManager.value(for: keyPath)) })
  15. }
  16. public convenience init(floats: CGFloat...) {
  17. self.init(v: { O2ThemeManager.element(for: floats) })
  18. }
  19. public required convenience init(arrayLiteral elements: CGFloat...) {
  20. self.init(v: { O2ThemeManager.element(for: elements) })
  21. }
  22. public required convenience init(stringLiteral value: String) {
  23. self.init(keyPath: value)
  24. }
  25. public required convenience init(unicodeScalarLiteral value: String) {
  26. self.init(keyPath: value)
  27. }
  28. public required convenience init(extendedGraphemeClusterLiteral value: String) {
  29. self.init(keyPath: value)
  30. }
  31. }
  32. public extension ThemeCGFloatPicker {
  33. class func pickerWithKeyPath(_ keyPath: String, map: @escaping (Any?) -> CGFloat?) -> ThemeCGFloatPicker {
  34. return ThemeCGFloatPicker(v: { map(O2ThemeManager.value(for: keyPath)) })
  35. }
  36. }
  37. @objc public extension ThemeCGFloatPicker {
  38. class func pickerWithKeyPath(_ keyPath: String) -> ThemeCGFloatPicker {
  39. return ThemeCGFloatPicker(keyPath: keyPath)
  40. }
  41. class func pickerWithFloats(_ floats: [CGFloat]) -> ThemeCGFloatPicker {
  42. return ThemeCGFloatPicker(v: { O2ThemeManager.element(for: floats) })
  43. }
  44. }
  45. extension ThemeCGFloatPicker: ExpressibleByArrayLiteral {}
  46. extension ThemeCGFloatPicker: ExpressibleByStringLiteral {}