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.
-
You can't put apple's default tabbar on the top. You have to make a custom tab bar for that – KrishnaCA Jun 04 '16 at 12:30
-
Is there any guides/kits for going about this? – Ryan Hampton Jun 04 '16 at 12:33
-
1https://github.com/xmartlabs/XLPagerTabStrip. This libray might help you in achieving this – KrishnaCA Jun 04 '16 at 12:36
-
That looks promising. Thank you – Ryan Hampton Jun 04 '16 at 12:39
-
Shall I write it as answer then? – KrishnaCA Jun 04 '16 at 12:39
-
Yep. Im happy to mark it correct for you. Thanks for your help – Ryan Hampton Jun 04 '16 at 12:48
4 Answers
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)!)

- 21
- 3
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

- 7,127
- 2
- 51
- 63
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. (:
-
-
This guy does not want to change for a normal view controller, the question is about tab bar controllers. – JBarros35 Jun 18 '20 at 10:09
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.

- 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