ThemeScrollViewIndicatorStylePicker.swift 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // ThemeScrollViewIndicatorStylePicker.swift
  3. // SwiftTheme
  4. //
  5. // Created by Jonathan Valldejuli on 12/23/18.
  6. // Copyright © 2018 Gesen. All rights reserved.
  7. //
  8. import UIKit
  9. @objc public final class ThemeScrollViewIndicatorStylePicker: ThemePicker {
  10. public convenience init(keyPath: String) {
  11. self.init(v: { ThemeScrollViewIndicatorStylePicker.getStyle(stringStyle: O2ThemeManager.string(for: keyPath) ?? "") })
  12. }
  13. public convenience init(keyPath: String, map: @escaping (Any?) -> UIScrollView.IndicatorStyle?) {
  14. self.init(v: { map(O2ThemeManager.value(for: keyPath)) })
  15. }
  16. public convenience init(styles: UIScrollView.IndicatorStyle...) {
  17. self.init(v: { O2ThemeManager.element(for: styles) })
  18. }
  19. public required convenience init(arrayLiteral elements: UIScrollView.IndicatorStyle...) {
  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. class func getStyle(stringStyle: String) -> UIScrollView.IndicatorStyle {
  32. switch stringStyle.lowercased() {
  33. case "default" : return .default
  34. case "black" : return .black
  35. case "white" : return .white
  36. default: return .default
  37. }
  38. }
  39. }
  40. public extension ThemeScrollViewIndicatorStylePicker {
  41. class func pickerWithKeyPath(_ keyPath: String, map: @escaping (Any?) -> UIScrollView.IndicatorStyle?) -> ThemeScrollViewIndicatorStylePicker {
  42. return ThemeScrollViewIndicatorStylePicker(v: { map(O2ThemeManager.value(for: keyPath)) })
  43. }
  44. class func pickerWithStyles(_ styles: [UIScrollView.IndicatorStyle]) -> ThemeScrollViewIndicatorStylePicker {
  45. return ThemeScrollViewIndicatorStylePicker(v: { O2ThemeManager.element(for: styles) })
  46. }
  47. }
  48. @objc public extension ThemeScrollViewIndicatorStylePicker {
  49. class func pickerWithKeyPath(_ keyPath: String) -> ThemeScrollViewIndicatorStylePicker {
  50. return ThemeScrollViewIndicatorStylePicker(keyPath: keyPath)
  51. }
  52. class func pickerWithStringStyles(_ styles: [String]) -> ThemeScrollViewIndicatorStylePicker {
  53. return ThemeScrollViewIndicatorStylePicker(v: { O2ThemeManager.element(for: styles.map(getStyle)) })
  54. }
  55. }
  56. extension ThemeScrollViewIndicatorStylePicker: ExpressibleByArrayLiteral {}
  57. extension ThemeScrollViewIndicatorStylePicker: ExpressibleByStringLiteral {}