1
votes

I customized my navigation bar to clear. So I set the backgroundImage as UIImage() and isTranslucent = true. So the problem I got here is: That is what I set in my xib. Now TopConstraints is: 10px enter image description here With topConstraint = 10. When I run in simulator iPhone 5s: this is what i got. The screen is perfect. Although I remember that, if I set isTranslucent = true -> I must set topConstraint is higher more than navigation bar height, ex: topConstraint = 50.enter image description here. But with this code, when I tried to run in real device: iPhone 5s. and this is what I got: enter image description here The navigation bar is cover the view. My simulator is run in iOS 11.0, and real device is run in iOS 9.2. Anyone have the same situation? Thanks so much

BTW: I need to set my navigation bar is clear because our background color is gradient color from top-left to bottom-right

1

1 Answers

2
votes

Remove backgroundImage as UIImage() and try this:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    self.navigationController?.navigationBar.isTranslucent = true
    self.navigationController?.navigationBar.backgroundColor = UIColor.clear
}

And keep the topConstraint = 10