AppearanceManager.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 = [.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 = [.foregroundColor: theme.colors.navigationbarTextColor]
  31. }
  32. let selectedBackgroundView = UIView()
  33. selectedBackgroundView.backgroundColor = theme.colors.mediaCategorySeparatorColor
  34. UITableViewCell.appearance().selectedBackgroundView = selectedBackgroundView
  35. // For the edit selection indicators
  36. UITableView.appearance().tintColor = theme.colors.orangeUI
  37. UISegmentedControl.appearance().tintColor = theme.colors.orangeUI
  38. UISwitch.appearance().onTintColor = theme.colors.orangeUI
  39. UISearchBar.appearance().barTintColor = .white
  40. UITabBar.appearance().tintColor = theme.colors.orangeUI
  41. if #available(iOS 10.0, *) {
  42. UITabBar.appearance().unselectedItemTintColor = theme.colors.cellDetailTextColor
  43. }
  44. UIPageControl.appearance().backgroundColor = theme.colors.background
  45. UIPageControl.appearance().pageIndicatorTintColor = .lightGray
  46. UIPageControl.appearance().currentPageIndicatorTintColor = theme.colors.orangeUI
  47. }
  48. @available(iOS 13.0, *)
  49. @objc class func navigationbarAppearance() -> UINavigationBarAppearance {
  50. let navBarAppearance = UINavigationBarAppearance()
  51. navBarAppearance.backgroundColor = PresentationTheme.current.colors.navigationbarColor
  52. navBarAppearance.titleTextAttributes = [.foregroundColor: PresentationTheme.current.colors.navigationbarTextColor]
  53. navBarAppearance.largeTitleTextAttributes = [.foregroundColor: PresentationTheme.current.colors.navigationbarTextColor]
  54. return navBarAppearance
  55. }
  56. }
  57. //extensions so that preferredStatusBarStyle is called on all childViewControllers otherwise this is not forwarded
  58. extension UINavigationController {
  59. override open var preferredStatusBarStyle: UIStatusBarStyle {
  60. return PresentationTheme.current.colors.statusBarStyle
  61. }
  62. override open var childForStatusBarStyle: UIViewController? {
  63. return self.topViewController
  64. }
  65. }