类似于 Facebook 的带有小图标和按钮的 TabBar。
TTTabBar 允许您创建具有以下功能的 TabBar:
配置
不支持
工作原理
将带有 TTTabBar 的 UIViewController 子类化,它可以在 storyboard 中,TTTabBar 是 UIViewController 的子类
创建 TabBar 项目,使用 TTTabBarItem,您可以使用 ViewController 或图片进行初始化。我建议如果标签项是标签,则使用 ViewController 进行初始化,如果元素是按钮,则使用图片进行初始化。然后您需要设置图片和选中图片
//Tab. VC -> UIViewController or subclass
let item = TTTabBarItem(viewController: vc)
item.image = UIImage(named: "image")
item.selectedImage = UIImage(named: "image_selected")
//Button
let item3 = TTTabBarItem(image: UIImage(named: "image"), selected: UIImage(named: image_selected"))
item3.isButton = true
//Configurations
item3.offsetBottom = 5
item3.offsetY = 5m
item3.backgroundColor = UIColor.blackColor()
item3.frame = CGRectMake(0, 0, 55, 55)
self.tabBackgroundColor = UIColor.lightGrayColor()
self.tabBarItems = [item, item2, item3, item4, item5]
self.updateTabBarView()
因为您对 TTTabBar 进行了子类化,所以您可以重写以下功能
//Default true
override func ttTabBar(tabBar: TTTabBar, shouldChangeTab tabBarItem: TTTabBarItem) -> Bool
override func ttTabBar(tabBar: TTTabBar, tabWillDisappear tabBarItem: TTTabBarItem)
override func ttTabBar(tabBar: TTTabBar, tabDidDisappear tabBarItem: TTTabBarItem)
override func ttTabBar(tabBar: TTTabBar, tabWillAppear tabBarItem: TTTabBarItem)
override func ttTabBar(tabBar: TTTabBar, tabDidAppear tabBarItem: TTTabBarItem)
//If the item has isButton = true, this method will be called
override func ttTabBar(tabBar: TTTabBar, buttonHasBeenClicked tabBarItem: TTTabBarItem)
程序化加载标签
//tabBarItem == nil. all the tabs will be deselected and the actual view will be deleted
func loadViewControllerFrom(tabBarItem: TTTabBarItem?)
加载不在 TabBar 项目上的视图
func loadViewController(vc: UIViewController)