1

Currently I have 1 tab view controller, with 3 menus:

enter image description here

But when running, the bottom menu / image are like being cutted or didn't show perfectly like this:

enter image description here

enter image description here

It should have 3 menus.

Code:

import UIKit
class TabBarReimbursementViewController: UITabBarController{

    var loadTable: Bool = false

    override func viewWillAppear(animated: Bool) {
        self.viewControllers![selectedIndex].viewWillAppear(true)
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        //        self.tabBar.barTintColor = UIColor.redColor()
        self.tabBar.tintColor = UIColor.blackColor()

        let addButton = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: #selector(TabBarReimbursementViewController.buttonClicked(_:)))

        navigationItem.rightBarButtonItem = addButton

        //       UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.whiteColor() ], forState: .Normal)

        UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.blackColor() ], forState: .Selected)

        let historySelected: UIImage! = UIImage(named: "history2.png")?.imageWithRenderingMode(.AlwaysOriginal)
        let approvalSelected: UIImage! = UIImage(named: "approve2.png")?.imageWithRenderingMode(.AlwaysOriginal)
        let listSelected: UIImage! = UIImage(named: "listlist2.png")?.imageWithRenderingMode(.AlwaysOriginal)

        (tabBar.items![1] ).selectedImage = historySelected
        (tabBar.items![0] ).selectedImage = approvalSelected
        (tabBar.items![2] ).selectedImage = listSelected

        self.selectedViewController = self.viewControllers![1]
        self.findHamburguerViewController()?.gestureEnabled = false
    }

    func buttonClicked(sender: UIBarButtonItem) {

        let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)

        let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("MyRequestForm") as! myRequestForm
        nextViewController.formType = "New"
        self.navigationController!.pushViewController(nextViewController, animated: true)

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Borom1r
  • 155
  • 1
  • 7
  • 18
  • you mean constraint in the tab bar controller or in the menu ? – Borom1r Dec 07 '16 at 03:36
  • pls check my picture, i added some. i think i didnt use constraint – Borom1r Dec 07 '16 at 04:11
  • Tab bar only works with navigation controller. You cannot directly join the tabbar controller to another view controller. You must embed sub view controllers in navigation controller and than try again. – KAR Dec 07 '16 at 05:33

2 Answers2

2

You CAPSPageMenu Library in which you can use tab bar controller very easily CAPSPageMenu

just add below code in Library

    _menuScrollView.translatesAutoresizingMaskIntoConstraints = NO;
    _menuScrollView.frame = CGRectMake(0.0, self.view.frame.size.width- _menuHeight,self.view.frame.size.width, _menuHeight);
SM18
  • 718
  • 7
  • 15
0

The thing is that what you are doing is not how a tab bar controller's tab bar items work. Each child view controller (there are three of them in your storyboard screen shot) has its own tabBarItem, and that is how the tab bar gets populated.

matt
  • 515,959
  • 87
  • 875
  • 1,141