2

I have a tableView that has a large navigation title of "My title". By default, when I scroll up, the large title turns into a small title. How do I go about hiding the small title during the small navigation bar but still show the large title when i scroll down? Is there a delegate i can use to notify me when navigation is transitioning for large title to small? Because my end result is to have my title be on the left bar bar button side when i scroll up.

Is there an easier to way move the title location to the left where left bar button would be?

My approach is create the left bar button with the same title as my navigation. I would hide it when my large navigation title is present then show it when large navigation title isnt. Meanwhile, I would hide the small navigation title when the small navigation bar is present. I hope this makes sense haha. Basically just trying to find a way to have my title on where the left bar button item should be.

Solution:

    self.navigationItem.title = "hello"
    let navBarAppearance = UINavigationBarAppearance()
    navBarAppearance.titlePositionAdjustment = UIOffset(horizontal: -150, vertical: 0)
    navBarAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
    navBarAppearance.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
    
    navigationController?.navigationBar.standardAppearance = navBarAppearance
    navigationController?.navigationBar.scrollEdgeAppearance = navBarAppearance
    
    navigationController?.navigationBar.prefersLargeTitles = true

enter image description here enter image description here

Kenny Ho
  • 409
  • 3
  • 16
  • "I hope this makes sense" yes!!!! I was trying to do this a while ago, but never found a solution. – aheze Apr 30 '21 at 01:37
  • I asked a kind of related question [here](https://stackoverflow.com/questions/65527339/get-the-default-shrunk-and-expanded-height-of-large-title-navigation-bar) but unfortunately the accepted answer didn't really work... – aheze Apr 30 '21 at 01:38
  • @aheze I found a solution, let me edit and show you. – Kenny Ho Apr 30 '21 at 01:43
  • You should post it as an answer :) – aheze Apr 30 '21 at 01:43

1 Answers1

1
    self.navigationItem.title = "My Title"

    let navBarAppearance = UINavigationBarAppearance()
    navBarAppearance.titlePositionAdjustment = UIOffset(horizontal: -150, vertical: 0)
    navBarAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
    navBarAppearance.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
    
    navigationController?.navigationBar.standardAppearance = navBarAppearance
    navigationController?.navigationBar.scrollEdgeAppearance = navBarAppearance
    
    navigationController?.navigationBar.prefersLargeTitles = true
Kenny Ho
  • 409
  • 3
  • 16