4

在将导航栏设置为透明后,我在恢复 iOS 11 大标题的 bartint 颜色时遇到问题。

复制步骤:

  1. 将导航栏背景图像和阴影设置为空 UIImage()。
  2. 导航栏变得透明。
  3. 将导航栏背景图像和阴影设置为 nil 并设置回栏色调颜色。
  4. 大标题导航栏变成白色;如果向下滚动(存在旧导航栏),那么您可以看到仅适用于旧式导航栏的条形颜色。

试过:

*将导航背景颜色和状态颜色设置为bar tint color,是的,它改变了,但没有像我们设置bar tint color那样的半透明视觉效果。

有没有人遇到和我一样的问题并且能够用任何解决方案或解决方法来解决它?

原来的

在此处输入图像描述

在浏览了一个带有透明导航的页面并返回后

在此处输入图像描述

仅供参考,我还应用自定义导航控制器从透明设置回默认颜色,

class CustomNavigationController: UINavigationController {

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

override func pushViewController(_ viewController: UIViewController, animated: Bool) {

    super.pushViewController(viewController, animated: animated)
   self.setDefaultNavigationBar()

}

override func popViewController(animated: Bool) -> UIViewController? {
    self.setDefaultNavigationBar()
    return super.popViewController(animated: animated)

}

override func popToViewController(_ viewController: UIViewController, animated: Bool) -> [UIViewController]? {
    self.setDefaultNavigationBar()
    return super.popToViewController(viewController, animated: animated)

}

override func popToRootViewController(animated: Bool) -> [UIViewController]? {
    self.setDefaultNavigationBar()
    return super.popToRootViewController(animated: animated)
}


func setDefaultNavigationBar() {

    let navigationBarColor = UIColor(hexString: "#00b5baff")!
    self.navigationBar.setBackgroundImage(nil, for: .default)
    self.navigationBar.shadowImage = nil
    //self.navigationController?.navigationBar.backgroundColor = UIColor.clear
    //self.navigationController?.navigationBar.tintColor = UIColor.clear
    self.navigationBar.barTintColor = navigationBarColor

}

/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/

}

4

2 回答 2

0

尝试提供 transparent.png 图像作为背景图像以实现透明度。那应该行得通。如果这不起作用,请尝试使用下面的代码来更新大标题颜色。

self.navigationController?.navigationBar.largeTitleTextAttributes = 
[NSAttributedStringKey.foregroundColor: UIColor.blue, 
 NSAttributedStringKey.font: UIFont(name: fontName, size: 30) ?? 
                             UIFont.systemFont(ofSize: 30)]

希望这可以帮助!

于 2018-01-04T23:18:33.173 回答
0

不确定这是否会对任何人有所帮助,但这对我有用时,当导航背景选择“喜欢大型标题”之后变成白色:

    let appearance = UINavigationBarAppearance()
    appearance.backgroundColor = FlatBlue()
    appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white]
    navigationBar.standardAppearance = appearance
    navigationBar.scrollEdgeAppearance = appearance
于 2019-10-31T11:39:47.617 回答