AppearanceManager.swift 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*****************************************************************************
  2. * AppearanceManager.swift
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2018 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Carola Nitz <nitz.carola # gmail.com>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. import UIKit
  13. @objc(VLCApperanceManager)
  14. class AppearanceManager: NSObject {
  15. @objc class func setupAppearance(theme: PresentationTheme = PresentationTheme.current) {
  16. // Change the keyboard for UISearchBar
  17. UITextField.appearance().keyboardAppearance = theme == PresentationTheme.darkTheme ? .dark : .light
  18. // For the cursor
  19. UITextField.appearance().tintColor = theme.colors.orangeUI
  20. // Don't override the 'Cancel' button color in the search bar with the previous UITextField call. Use the default blue color
  21. let attributes = [NSAttributedString.Key.foregroundColor: theme.colors.orangeUI]
  22. UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).setTitleTextAttributes(attributes, for: .normal)
  23. UINavigationBar.appearance().barTintColor = theme.colors.navigationbarColor
  24. UINavigationBar.appearance(whenContainedInInstancesOf: [VLCPlaybackNavigationController.self]).barTintColor = nil
  25. UINavigationBar.appearance().tintColor = theme.colors.orangeUI
  26. UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: theme.colors.navigationbarTextColor]
  27. if #available(iOS 11.0, *) {
  28. UINavigationBar.appearance().prefersLargeTitles = true
  29. UINavigationBar.appearance(whenContainedInInstancesOf: [VLCPlaybackNavigationController.self]).prefersLargeTitles = false
  30. UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: theme.colors.navigationbarTextColor]
  31. }
  32. // For the edit selection indicators
  33. UITableView.appearance().tintColor = theme.colors.orangeUI
  34. UISegmentedControl.appearance().tintColor = theme.colors.orangeUI
  35. UISwitch.appearance().onTintColor = theme.colors.orangeUI
  36. UISearchBar.appearance().barTintColor = .white
  37. UITabBar.appearance().tintColor = theme.colors.orangeUI
  38. if #available(iOS 10.0, *) {
  39. UITabBar.appearance().unselectedItemTintColor = theme.colors.cellDetailTextColor
  40. }
  41. UIPageControl.appearance().backgroundColor = theme.colors.background
  42. UIPageControl.appearance().pageIndicatorTintColor = .lightGray
  43. UIPageControl.appearance().currentPageIndicatorTintColor = theme.colors.orangeUI
  44. }
  45. }
  46. //extensions so that preferredStatusBarStyle is called on all childViewControllers otherwise this is not forwarded
  47. extension UINavigationController {
  48. override open var preferredStatusBarStyle: UIStatusBarStyle {
  49. return PresentationTheme.current.colors.statusBarStyle
  50. }
  51. override open var childForStatusBarStyle: UIViewController? {
  52. return self.topViewController
  53. }
  54. }