Change NavigationBar Size with AdditionalSafeAreaInsets

Jun 21, 2020


If you ever want something like this: Simulator Screen Shot - iPhone 11 Pro Max - 2020-06-22 at 15.04.55 Screen Shot 2563-06-22 at 15.04.04 simply add this line to your viewController

  navigationController? = 100 
  // where 100 is the extra space

To see the code in action, I attached the following function to the BLUE slider

  @IBAction func sliderSlided(_ sender: Any) {
        let top: CGFloat = (CGFloat(200 * ((sender as? UISlider)?.value ?? 1) - 0.5))
        navigationController? = top


Also notice that when the NavigationBar changes, the slideIndicator changes too, indicating change in the view's size.

I also add a RED slider with the following function:

    @IBAction func slider2Slided(_ sender: Any) {
        let top: CGFloat = (CGFloat(100 * ((sender as? UISlider)?.value ?? 1))) = top


Notice how RED slider resizes both the content and the Navigation Bar. Moiving the BLUE slider after the RED to configure the navigationBar.


AdditionalSafeAreaInsets is traditionally use to change the safeAreaInset of the ViewController.


© 2015 - 2021