2016-12-07 163 views
0

目前,我有1個視圖控制器,具有3個菜單:標籤欄項目將不會顯示

enter image description here

但是運行的時候,底部菜單/圖象都像被板缺或不完美展現像這樣:

enter image description here

enter image description here

應該有3個菜單。

代碼:

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. 
    } 

} 
+0

你的意思是在標籤欄控制器或在菜單約束? – Borom1r

+0

請檢查我的照片,我加了一些。我想我沒有使用約束 – Borom1r

+0

標籤欄只能用於導航控制器。您不能直接將TabBar控制器連接到另一個視圖控制器。您必須在導航控制器中嵌入子視圖控制器,然後重試。 – KAR

回答

0

的事情是,你在做什麼是標籤欄控制器的標籤欄項目並不怎麼工作的。每個子視圖控制器(其中有三個在你的故事板屏幕截圖中)有它自己的tabBarItem,這就是標籤欄被填充的方式。

2

您CAPSPageMenu庫中,你可以使用很容易CAPSPageMenu

標籤欄控制器剛剛在庫,添加以下代碼

_menuScrollView.translatesAutoresizingMaskIntoConstraints = NO; 
    _menuScrollView.frame = CGRectMake(0.0, self.view.frame.size.width- _menuHeight,self.view.frame.size.width, _menuHeight);