0

So the way I understand navigation bar (navigation item) is that it has three locations you can modify, which is left (leftBarButtomItem), middle (titleView), and right (rightBarButtonItem).

Now what I'm going to achieve is that I want to just add a simple progress bar line at the very bottom of navigation bar, but still inside navigation bar. I want to make this like an extension of navigation bar that I can reuse on other screens. But I want that left, middle, and right "views" are still working like usual. e.g. I don't want that if I change the title view content manually in other view controller, then the line disappears / stops working for that other view controller. So this will feel like an independent overlay added on top of navigation bar as subview, separated from leftBarButtonItem, titleView, and rightBarButtonView, sort to speak.

Is it possible to do that in navigation item?

4
  • 1
    You can use navigation bar addSubview(:_) to add any view you like directly. Commented Nov 6, 2018 at 2:48
  • @E.Coms oo I didn't even check whether navigation item has addSubView or not. I'm too fixated to the bar buttons and titleView. how amateur of me. Thanks! Commented Nov 6, 2018 at 3:21
  • 1
    not navigationItem , but navigationBar. They are different Commented Nov 6, 2018 at 3:36
  • Oh okay, so it is at navigation controller then. Thanks! Commented Nov 6, 2018 at 7:13

1 Answer 1

0

This is a example of how to add a Image instead of a Title String

fileprivate func setupTitle(){

    let logo = UIImage(named: "my_incredible_logo")
    let imageView = UIImageView(image:logo)
    imageView.contentMode = .scaleAspectFit

    self.navigationItem.titleView = imageView
    self.navigationController?.navigationBar.prefersLargeTitles = false
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yea, I understand this. But the problem is this stops titleView from working as it should be (e.g. to let other view controller that uses this to set their own titleView because that will overwrite the incredible_logo image). I need an overlay view solution that kinds of floating on top of navigation bar and didn't change titleView at all (can be managed separately). Some folks has already throw a solution in the comment that I can add subview to navigation bar directly, instead of using navigation item.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.