状态栏灯光内容未出现在导航控制器

状态栏灯光内容未出现在导航控制器

本文介绍了使用拆分视图控制器,状态栏灯光内容未出现在导航控制器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

当添加状态栏作为灯光内容时.它在登录屏幕上显示正常.在登录屏幕上变为白色.成功登录后,我有一个拆分视图和导航控制器.

When adding status bar as light content. its appearing fine in login screen. it changes to white in login screen. after successful login I have an split view and navigation controller.

我已经添加了代码,但仍然显示黑色.

I have added the code but still it shows black.

1)在视图控制器的行下方添加了.

1) added below line in view contoller.

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}

2)info.plist

2) info.plist

View controller-based status bar appearance -> NO

3)然后碰到了这一行,并且也添加了这一行.

3) then came across this line and added this one also.

  controller.navigationController?.navigationBar.barTintColor = UIColor.white

4)然后遇到了一篇文章,其中提到如果我们需要更改导航中的状态栏,则添加扩展名,但仍然没有任何效果

4) then came across article where it was mentioned to add extension if we need to change status bar in navigation but still nothing works

extension UINavigationController
{
    override open var preferredStatusBarStyle: UIStatusBarStyle {
        get {
            return .lightContent
        }
    }
}

我已经添加并尝试了其中的每一个,但仍然显示黑色状态栏.

I have added and tried with each of them but still it shows black status bar.

推荐答案

导航控制器存在相同的问题.但我可以通过以下方式解决它.

步骤1:创建自定义导航类

import UIKit


class CustomNavigationController: UINavigationController {
    override var preferredStatusBarStyle: UIStatusBarStyle {
        return topViewController?.preferredStatusBarStyle ?? .default
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)

        let appearance = UINavigationBarAppearance()
        appearance.configureWithOpaqueBackground()

        appearance.titleTextAttributes = [.foregroundColor: UIColor.white]
        appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
        appearance.backgroundColor = .systemIndigo

        navigationBar.standardAppearance = appearance
        navigationBar.scrollEdgeAppearance = appearance
        navigationBar.prefersLargeTitles = true
    }
}

第2步::使用此类可为NavigationColtroller子类化.

Step2: Use this class to subclass your NavigationColtroller.

第3步:转到已嵌入导航控制器的ViewController.

Step3: Go to your ViewController who is embedded with a navigation controller.

Stpe4:将这一行代码放入viewDidLoad()

Stpe4: Put this line of code in viewDidLoad()


// MARK:-  Lifecycle Methods
    override func viewDidLoad() {
self.navigationController?.navigationBar.barStyle = .black
}

第5步:您可以在ViewController中覆盖方法

Step5: You can override a method in ViewController

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
      }

你很好.如果您有任何疑问,请发表评论

You are good to go. If you have any doubt plz comment

这篇关于使用拆分视图控制器,状态栏灯光内容未出现在导航控制器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 14:18