ThemeKeyboardAppearancePicker.swift 2.6 KB

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