0

I've just added a navigation bar to my Swift tabbed application. I have moved it down by 20 so that it lines up with the status bar however there is now obviously a gap at the top. Apps in iOS seem to match the navigation bar to the status bar colour so I was wondering if anyone could let me know how I get my app to match the nav bar colour and the status bar colour?

Thanks

user3746428
  • 11,047
  • 20
  • 81
  • 137
  • How are you able to make it taller? I can only find an option for increasing the width. – user3746428 Jul 08 '14 at 02:29
  • I set the height using an auto layout constraint (the status bar doesn't appear in landscape mode on iPhone so I set the height to 64 for the "Any Width, Regular Height" size class) – Jiaaro Jul 08 '14 at 02:57
  • Try this, if you don't want to embed a navigation controller : http://stackoverflow.com/questions/18737186/position-of-navigation-bar-for-modal-view-ios7 – Ketul Patani May 11 '16 at 19:27

1 Answers1

0

You should not be adding a navigation bar manually to your view. It is far easier and ideal to use a UINavigationController instead. Instead of putting a view controller directly as one of the tabs, wrap it in a UINavigationController and put that as the tab's view controller. Then the positioning and sizing will be handled for you and you will be better setup for future releases of iOS.

var myController = MyController()
var navController = UINavigationController(rootViewController: myController)
// use navController wherever you were using myController before
drewag
  • 93,393
  • 28
  • 139
  • 128
  • This is my first application so I am not confident in all of the terminology. Could you explain the steps I would take to achieve what you are suggesting? What I currently have is a tab view controller with a first view controller and a second view controller connected to it. – user3746428 Jul 08 '14 at 12:05
  • @user3746428 Are you setting up your tab controller in a Storyboard or in code? – drewag Jul 08 '14 at 16:21
  • I'm using storyboard. – user3746428 Jul 08 '14 at 18:48
  • @user3746428 so instead of connecting your tab view controller directly to you view controller, put a UINavigationController in-between. UINavigationController is one of the objects you can drag onto the storyboard. – drewag Jul 08 '14 at 19:15
  • Ah! I've just started learning Swift and Xcode so I still have a lot to learn but that works perfectly. Thanks a lot! – user3746428 Jul 08 '14 at 19:50
  • Glad I could help. Yup, learning is just about solving one problem at a time :) – drewag Jul 08 '14 at 20:00