4

I having a problem in restoring back the bartint color for iOS 11 large title after had set the navigationbar to transparent.

Reproduction step:

  1. Set the navigation bar background image and shadow to empty UIImage().
  2. The navigation bar became transparent.
  3. Set the navigation bar background image and shadow to nil and set back the bar tint color.
  4. The large title navigation bar became white color; if scroll down(the old navigation bar present) then you can see the bar tint color only applied to old style navigation bar.

Tried:

*Set the navigation background color and status color to the bar tint color, yes it changed but without translucent visual effect like we set bar tint color.

Does anyone has face the same problem as me and able to fix it with any solution or workaround ?

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.
}
*/

}

Jack Kyeteo
  • 109
  • 1
  • 7

2 Answers2

0

Try providing transparent.png image as background image to achieve the transparency. That should work. If that doesn't work try using below code to just update the large title colors.

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

Hope this helps!

torap
  • 656
  • 6
  • 15
  • Not really get that, the transparent.png you refer here is a totally transparent image file ? and how can be setting bar tint color to achieve my title color ? – Jack Kyeteo Jan 08 '18 at 08:26
  • yes, transparent.png means a transparent image which should be applied to navigation bar background to make it transparent and yes barTintColor was not correct sentence I have removed that from answer. The code above which I provided for title color change should work. Isn't that working for you? – torap Jan 08 '18 at 16:34
  • I think you got my question wrong, I did managed to change my large title font color whereas the bartintcolor is not able to change back for the largetitle. I do update my question with photos and code. thanks anyway! – Jack Kyeteo Jan 10 '18 at 04:25
0

Not sure if this will help anyone, but this is what worked for me when the navigation background tint became white after selecting 'Prefers Large Titles' :

    let appearance = UINavigationBarAppearance()
    appearance.backgroundColor = FlatBlue()
    appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white]
    navigationBar.standardAppearance = appearance
    navigationBar.scrollEdgeAppearance = appearance
JohnnyD
  • 180
  • 10