目前我有1个标签视图控制器,有3个菜单:
但是在运行时,底部的菜单/图像就像被剪切或者没有像这样完美地显示:
应该有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 :(得分:2)
您可以非常轻松地使用标签栏控制器的CAPSPageMenu库CAPSPageMenu
只需在库
中添加以下代码即可 _menuScrollView.translatesAutoresizingMaskIntoConstraints = NO;
_menuScrollView.frame = CGRectMake(0.0, self.view.frame.size.width- _menuHeight,self.view.frame.size.width, _menuHeight);
答案 1 :(得分:0)
问题是你正在做的不是标签栏控制器的标签栏项目如何工作。每个子视图控制器(故事板屏幕截图中有三个)都有自己的 tabBarItem
,这就是标签栏的填充方式。