StatusBar

import Foundation
import UIKit

extension UITabBarController {
    /// 控制各子控制器的状态栏样式(白色、黑色)
    open override var childForStatusBarStyle: UIViewController? {
        return selectedViewController
    }
    
    open override var preferredStatusBarStyle: UIStatusBarStyle {
        return selectedViewController?.preferredStatusBarStyle ?? UIStatusBarStyle.default
    }
    
    open override var prefersStatusBarHidden: Bool {
        return selectedViewController?.prefersStatusBarHidden ??  false
    }
    
    public override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
        return selectedViewController?.preferredStatusBarUpdateAnimation ?? UIStatusBarAnimation.none
    }
}

extension UINavigationController {
    /// 控制各子控制器的状态栏样式(白色、黑色)
    open override var childForStatusBarStyle: UIViewController? {
        return topViewController
    }
    
    open override var preferredStatusBarStyle: UIStatusBarStyle {
        return topViewController?.preferredStatusBarStyle ?? UIStatusBarStyle.default
    }
    
    open override var prefersStatusBarHidden: Bool {
        return topViewController?.prefersStatusBarHidden ??  false
    }
    
    open override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
        return topViewController?.preferredStatusBarUpdateAnimation ?? UIStatusBarAnimation.none
    }
}

extension UISplitViewController {
    open override var childForStatusBarStyle: UIViewController? {
        return viewControllers.first
    }
}

你可能感兴趣的:(StatusBar)