ThemeImagePicker.swift 2.0 KB

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