1

I am using a navigation controller and my navigation bar will not extend to the top of the screen. I never had an issue with this until I updated Xcode to version 13.0. I am using storyboard and can't figure out why this issue is happening. (See photo)

screenshot of storyboard

Ethan Brimhall
  • 357
  • 3
  • 10
  • please share some code. Including your constraints. – Jacob Oct 09 '21 at 22:53
  • I am not using any code or constraints. I just dragged a navigation controller onto the storyboard and this is what it looks like. – Ethan Brimhall Oct 10 '21 at 16:39
  • 1
    Ahh its a navigation controller. Makes sense. I don't use storyboards. I'm not even sure you can do this on storyboards. Here is how you would do it programatically. Look at the examples using `UINavigationBar.appearance()` if you wanna change it everywhere in the app: https://stackoverflow.com/questions/24687238/changing-navigation-bar-color-in-swift?rq=1. Just place the code in your `AppDelegate` `didFinishLaunchingWithOptions` function. Edit: Oh you can set it on storyboards, just enable "Scroll Edge" and set the background of Scroll Edge – Jacob Oct 11 '21 at 01:34

1 Answers1

1

If you are looking for how to make it with storyboards, simply turn on "Scroll Edge" in the attributes inspector, while you tap on the Navigation bar...image here

If you are not using storyboards, try setting a delegate object for the navigation bar.

navigationBar.delegate = self

Conform UIBarPositioningDelegate in your delegate object and attach bar to the top

ViewController: UIViewController, UIBarPositioningDelegate {
func position(for bar: UIBarPositioning) -> UIBarPosition {
    return .topAttached
}
DmitryKhm
  • 11
  • 3