ThemeStatusBarStylePicker.swift 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // ThemeStatusBarStylePicker.swift
  3. // SwiftTheme
  4. //
  5. // Created by Gesen on 2017/1/28.
  6. // Copyright © 2017年 Gesen. All rights reserved.
  7. //
  8. import UIKit
  9. #if os(tvOS)
  10. final class ThemeStatusBarStylePicker: ThemePicker {}
  11. #else
  12. @objc public final class ThemeStatusBarStylePicker: ThemePicker {
  13. var animated = true
  14. public convenience init(keyPath: String) {
  15. self.init(v: { ThemeStatusBarStylePicker.getStyle(stringStyle: O2ThemeManager.string(for: keyPath) ?? "") })
  16. }
  17. public convenience init(keyPath: String, map: @escaping (Any?) -> UIStatusBarStyle?) {
  18. self.init(v: { map(O2ThemeManager.value(for: keyPath)) })
  19. }
  20. public convenience init(styles: UIStatusBarStyle...) {
  21. self.init(v: { O2ThemeManager.element(for: styles) })
  22. }
  23. public required convenience init(arrayLiteral elements: UIStatusBarStyle...) {
  24. self.init(v: { O2ThemeManager.element(for: elements) })
  25. }
  26. public required convenience init(stringLiteral value: String) {
  27. self.init(keyPath: value)
  28. }
  29. public required convenience init(unicodeScalarLiteral value: String) {
  30. self.init(keyPath: value)
  31. }
  32. public required convenience init(extendedGraphemeClusterLiteral value: String) {
  33. self.init(keyPath: value)
  34. }
  35. class func getStyle(stringStyle: String) -> UIStatusBarStyle {
  36. switch stringStyle.lowercased() {
  37. case "default" : return .default
  38. case "lightcontent" : return .lightContent
  39. default: return .default
  40. }
  41. }
  42. }
  43. public extension ThemeStatusBarStylePicker {
  44. class func pickerWithKeyPath(_ keyPath: String, map: @escaping (Any?) -> UIStatusBarStyle?) -> ThemeStatusBarStylePicker {
  45. return ThemeStatusBarStylePicker(v: { map(O2ThemeManager.value(for: keyPath)) })
  46. }
  47. class func pickerWithStyles(_ styles: [UIStatusBarStyle]) -> ThemeStatusBarStylePicker {
  48. return ThemeStatusBarStylePicker(v: { O2ThemeManager.element(for: styles) })
  49. }
  50. }
  51. @objc public extension ThemeStatusBarStylePicker {
  52. class func pickerWithKeyPath(_ keyPath: String) -> ThemeStatusBarStylePicker {
  53. return ThemeStatusBarStylePicker(keyPath: keyPath)
  54. }
  55. class func pickerWithStringStyles(_ styles: [String]) -> ThemeStatusBarStylePicker {
  56. return ThemeStatusBarStylePicker(v: { O2ThemeManager.element(for: styles.map(getStyle)) })
  57. }
  58. }
  59. extension ThemeStatusBarStylePicker: ExpressibleByArrayLiteral {}
  60. extension ThemeStatusBarStylePicker: ExpressibleByStringLiteral {}
  61. #endif