1

I want to have the Tab Bar at the top of the screen. One post suggested to do the followings (I put the following code in the viewDidLoad() of the UITabBarController) :

CODE

let tabBar = self.tabBar

// yStatusBar indicates the height of the status bar
let yStatusBar = UIApplication.sharedApplication().statusBarFrame.size.height

// Set the size and the position in the screen of the tab bar
tabBar.frame = CGRectMake(0, yStatusBar, tabBar.frame.size.width, tabBar.frame.size.height)

There are 2 problems with this solution:

  1. The bottom of the screen is left with a black region where the tab bar was

  2. The Tab bar covers the view at the top of the screen - the constraints of that view is relative to the device but they should be relative to the Tab bar. However when the screen is designed in the IB there is no Tab bar to relate to.

Is there a way to overcome these problems? P.S. I am new to IOS

Zvi
  • 2,354
  • 2
  • 26
  • 37
  • This is against the human interface guidelines and might not be a good idea. If you are still at it, look at the answer at: http://stackoverflow.com/questions/29579992/positioning-uitabbar-at-the-top – realtimez Aug 16 '16 at 22:56
  • 1
    I have my app written for Android and I am porting it now to iPhone. In Android that is the way most app work. – Zvi Aug 17 '16 at 18:01

2 Answers2

1
let tabBar = self.tabBarController?.tabBar
// Set the size and the position in the screen of the tab bar
tabBar?.frame = CGRect(x: 0, y: self.view.frame.height, width: (tabBar?.frame.size.width)!, height:  (tabBar?.frame.size.height)!)
Raju Abe
  • 735
  • 2
  • 10
  • 25
Shami
  • 11
  • 2
0

Although it is against the human interface guidelines there exist a hack if you really want to.

You could create a blank UIView in your storyboard (with proper constraints set up) that would essentially be the placeholder for the tabBar when loaded.

You then set top constraints for your other views relative to this view that you have setup.

This works, but probably not best practice to do so

velociraptor11
  • 576
  • 1
  • 5
  • 10