Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change UITabBar height

I use UITabBarController as a root view and app supports iOS 6 and above. Project class hierarchy is as below.

UITabBarController   - tab1     - UINavigationController       - UIViewController       - UIViewController       .       .   - tab2     - UINavigationController       - UIViewController       - UIViewController       .       .       .   - tab3     - UIViewController   - tab4     - UIViewController 

I used below code to change height of UITabBar in one of the UIViewControllers (which is inside UINavigationController) in above hierarchy.

CGRect tabbarFrame = self.tabBarController.tabBar.frame; tabbarFrame.size.height += 60; self.tabBarController.tabBar.frame = tabbarFrame; 

But its not changing the height. UITabBar is displayed with default height. Though logging its value prints changed value as shown below.

<UITabBar: 0xb528f60; frame = (0 431; 320 109); autoresize = W+TM; layer = <CALayer: 0xb529080>> 

How can I change UITabBar's height to achieve something like this:?

enter image description here

like image 806
Geek Avatar asked Apr 13 '14 14:04

Geek


People also ask

How do I change the height of my tab bar?

But, the Height of TabBar can be changed by setting SizeFactor property of TabBarSplitterControl. When SizeFactor changed, TabBar Height will be changed with the new value by multiplying the SystemInformation. HorizontalScrollBarHeight with SizeFactor.

How do I create a custom tab bar in Swift?

To add a Tab Bar Controller to the Storyboard, select the 4 placeholders that we just created and the View Controller. Then, go to Editor, select Embed in and Tab Bar Controller. This will envelop all those scenes in a single Tab Bar Controller. Put the new Tab Bar Controller on top of the other controllers.

What is tab bar controller in Swift?

What's A Tab Bar Controller? A tab bar controller, of class UITabBarController, is a container view controller. It typically organizes 3-5 view controllers in a group. The user of your app can switch between view controllers by tapping one of the tabs in the tab bar at the bottom of the screen.


1 Answers

I faced this issue and I was able to solve it.

You have to add following code to your subclass of UITabBarController class.

const CGFloat kBarHeight = 80;  - (void)viewWillLayoutSubviews {     [super viewWillLayoutSubviews];      CGRect tabFrame = self.tabBar.frame; //self.TabBar is IBOutlet of your TabBar     tabFrame.size.height = kBarHeight;     tabFrame.origin.y = self.view.frame.size.height - kBarHeight;     self.tabBar.frame = tabFrame; } 

Swift:

override func viewWillLayoutSubviews() {     super.viewWillLayoutSubviews()      tabBar.frame.size.height = kBarHeight     tabBar.frame.origin.y = view.frame.height - kBarHeight } 
like image 196
Rushikesh Avatar answered Oct 16 '22 23:10

Rushikesh