AppearanceManager.swift 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. }
  39. }
  40. //extensions so that preferredStatusBarStyle is called on all childViewControllers otherwise this is not forwarded
  41. extension UINavigationController {
  42. override open var preferredStatusBarStyle: UIStatusBarStyle {
  43. return PresentationTheme.current.colors.statusBarStyle
  44. }
  45. }