AppearanceManager.swift 2.63 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*****************************************************************************
 * AppearanceManager.swift
 * VLC for iOS
 *****************************************************************************
 * Copyright (c) 2018 VideoLAN. All rights reserved.
 * $Id$
 *
 * Authors: Carola Nitz <nitz.carola # gmail.com>
 *
 * Refer to the COPYING file of the official project for license.
 *****************************************************************************/
import UIKit

@objc(VLCApperanceManager)
15 16 17
class AppearanceManager: NSObject {

    @objc class func setupAppearance(theme: PresentationTheme = PresentationTheme.current) {
18 19 20 21 22 23
        // Change the keyboard for UISearchBar
        UITextField.appearance().keyboardAppearance = theme == PresentationTheme.darkTheme ? .dark : .light
        // For the cursor
        UITextField.appearance().tintColor = theme.colors.orangeUI

        // Don't override the 'Cancel' button color in the search bar with the previous UITextField call. Use the default blue color
Soomin Lee's avatar
Soomin Lee committed
24
        let attributes = [NSAttributedString.Key.foregroundColor: theme.colors.orangeUI]
25 26
        UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).setTitleTextAttributes(attributes, for: .normal)

27
        UINavigationBar.appearance().barTintColor = theme.colors.navigationbarColor
28
        UINavigationBar.appearance(whenContainedInInstancesOf: [VLCPlaybackNavigationController.self]).barTintColor = nil
29
        UINavigationBar.appearance().tintColor = theme.colors.orangeUI
Soomin Lee's avatar
Soomin Lee committed
30
        UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: theme.colors.navigationbarTextColor]
31 32 33

        if #available(iOS 11.0, *) {
            UINavigationBar.appearance().prefersLargeTitles = true
Kevin Bettin's avatar
Kevin Bettin committed
34
            UINavigationBar.appearance(whenContainedInInstancesOf: [VLCPlaybackNavigationController.self]).prefersLargeTitles = false
Soomin Lee's avatar
Soomin Lee committed
35
            UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: theme.colors.navigationbarTextColor]
36 37 38 39 40 41 42 43 44 45
        }
        // For the edit selection indicators
        UITableView.appearance().tintColor = theme.colors.orangeUI
        UISegmentedControl.appearance().tintColor = theme.colors.orangeUI
        UISwitch.appearance().onTintColor = theme.colors.orangeUI
        UISearchBar.appearance().barTintColor = .white

        UITabBar.appearance().tintColor = theme.colors.orangeUI
    }
}
46 47 48

//extensions so that preferredStatusBarStyle is called on all childViewControllers otherwise this is not forwarded
extension UINavigationController {
Soomin Lee's avatar
Soomin Lee committed
49
    override open var childForStatusBarStyle: UIViewController? {
50 51 52
        return self.topViewController
    }
}