Search code examples
iosswiftuitableviewuikituinavigationbar

Attach UINavigationBar to UIScrollView to get shrinking title


I have a UIViewController with a UITableView inside. I am required to have this in a UIViewController and not in a UINavigationController to support some other features in the design of the app. In iOS 11 and later, Apple introduced a large title effect to UINavigationBars that shrinks when the user scrolls down. How can I achieve this behaviour without using a UITableViewController?


Solution

  • You can just put a UITableView/ Scroll view and give bottom and top constraints with respect to superview as 0.

    And when presenting this page put it inside as rootViewController in let rootVc = UINavigationController(rootViewController: 'your view controller') also enable rootVC.preferredLargeTitle = true

    So if your tableView has more cells and when you scroll the navigation bar will shrink by itself.