2

Currently my tab bar controller is at the bottom of the view controller. I was wondering if there is a way to move it to the top of the view controller as I cant seem to find any documentation on it.

Ryan Hampton
  • 319
  • 1
  • 4
  • 21

4 Answers4

2

Swift 3

let rect = self.tabBar.frame;
self.tabBar.frame  = rect.insetBy(dx: 0, dy:  -view.frame.height + self.tabBar.frame.height + (self.navigationController?.navigationBar.frame.height)!)
Phong
  • 21
  • 3
0

Swift 5 | Xcode 11

Try overriding viewWillLayoutSubviews() in your class that extends UITabBarController and then put following:-

override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()

    self.tabBar.invalidateIntrinsicContentSize()

    var tabSize: CGFloat = 44.0;

    var orientation: UIInterfaceOrientation = UIApplication.shared.statusBarOrientation

    if (orientation.isLandscape) {
        tabSize = 32.0;
    }

    var tabFrame: CGRect = self.tabBar.frame;

    tabFrame.size.height = tabSize;

    tabFrame.origin.y = self.view.frame.origin.y;

    self.tabBar.frame = tabFrame;

    // Set the translucent property to false then back to true to
    // force the UITabBar to reblur, otherwise part of the
    // new frame will be completely transparent if we rotate
    // from a landscape orientation to a portrait orientation.

    self.tabBar.isTranslucent = false;
    self.tabBar.isTranslucent = true;
}

Reference: https://stackoverflow.com/a/29580094/6117565

bikram
  • 7,127
  • 2
  • 51
  • 63
-1

You can try using UIViewController instead of UITabBarController and then place TabBar control on top in your view by constraints. Another way is create your own tabbar. (:

Emily
  • 96
  • 1
  • 11
Mr. A
  • 704
  • 1
  • 7
  • 16
-1

You can't change position on UITabbar. Read Apple documentation for tabbar.

If you want to set effect like tabbar on top of viewController then You can manage that by using one uiview of same size of tabbar and multiple uibuttons in that view which works as tabs. And set that view at top or any position at which you want to show tabbar. You have to manage viewcontrollers displays on button click and manage that view to every view controller. So it is very difficult task, so it is better to use default tabbarController provided by system.

Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
  • I fell like I want to give it a try, do you happen to have any guides or advice on where to start? – Ryan Hampton Jun 04 '16 at 11:00
  • That is very critical to explain here. You have to manage it. Second thing you can take `uitabbar` from interface and can place at top so research for that if you can use custom tabbar instead of tabbarcontroller. I haven't use it still so no much idea. – Ketan Parmar Jun 04 '16 at 11:10