首页 文章

iOS 11大 Headers 栏色调无法设置

提问于
浏览
4

在将导航栏设置为透明后,我在恢复iOS 11大 Headers 的bartint颜色方面遇到了问题 .

Reproduction step:

  • 将导航栏背景图像和阴影设置为空UIImage() .

  • 导航栏变得透明 .

  • 将导航栏背景图像和阴影设置为nil并设置条纹色调 .

  • 大 Headers 导航栏变为白色;如果向下滚动(旧的导航栏存在),那么您可以看到仅应用于旧式导航栏的条形色调颜色 .

Tried:

*将导航背景颜色和状态颜色设置为条纹色调,是的它已更改但没有半透明的视觉效果,就像我们设置条纹色调一样 .

有没有人遇到与我相同的问题,并能够解决任何解决方案或解决方法?

Original

enter image description here

After went through a page with transparent navigation and come back

enter image description here

FYI, I also apply custom navigation controller to set back from transparent to default 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.
}
*/

}

1 回答

  • 0

    尝试提供transparent.png图像作为背景图像以实现透明度 . 这应该工作 . 如果这不起作用尝试使用下面的代码来更新大 Headers 颜色 .

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

    希望这可以帮助!

相关问题