Search code examples
iosobjective-cxcodeios10uinavigationitem

navigationItem.TitleView not working on iOS 10


I have a problem with a titleview in navigationBar. The thing is that its not displayed when i assign a view into titleView. I've tried to use navigationItem.title = @"eqweqweq"; but nothing happens.

This view involved is created by code, i dont know if that's the problem, because the other ViewControllers where i've used that worked perfectly.

Is there any bug in iOS 10 that i cant use titleView? Sometimes it works sometimes not.

I've search on google but nothing helped me. I hope somebody can help me T_T.

thank you


Solution

  • Finally i've solved the problem!

    The problem was this function:

    extension UINavigationController{
    func applyWhiteEffect(){
            var bounds = self.navigationBar.bounds
            let whiteView = UIView()
            bounds.origin.y = -20
            bounds.size.height = bounds.size.height + 20
            whiteView.frame = bounds
            whiteView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
            whiteView.userInteractionEnabled = false
            whiteView.backgroundColor = UIColor.whiteColor()
            whiteView.tag = 1000
            self.navigationBar.addSubview(whiteView)
            self.navigationBar.backgroundColor = UIColor.clearColor()
            self.navigationBar.sendSubviewToBack(whiteView)
        }
    }
    

    This function applied a white view and there was a problem with that and iOS 10, so i've changed to this:

    func applyWhiteEffect(){
            var bounds = self.navigationBar.bounds
            let whiteView = UIView()
            bounds.origin.y = -20
            bounds.size.height = 20
            whiteView.frame = bounds
            whiteView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
            whiteView.userInteractionEnabled = false
            whiteView.backgroundColor = UIColor.whiteColor()
            whiteView.tag = 1000
            self.navigationBar.addSubview(whiteView)
            self.navigationBar.backgroundColor = UIColor.whiteColor()
            self.navigationBar.sendSubviewToBack(whiteView)
        }
    

    Changing the view to only cover status bar and self.navigationBar.backgroundColor = UIColor.whiteColor()

    Thanks guys for helping me anyway :D