TTTabBar 1.1.1

TTTabBar 1.1.1

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2015年11月
SPM支持 SPM

Edig 维护。



TTTabBar 1.1.1

  • Eduardo Iglesias

TTTabBar

类似于 Facebook 的带有小图标和按钮的 TabBar。

alt tag

TTTabBar 允许您创建具有以下功能的 TabBar:

  • 每个标签的不同尺寸
  • 将每个标签元素设置为由标签或按钮
  • 可以随时更新 tabBar 的大小、颜色和元素
  • 程序化加载标签
  • 加载不在标签中的视图

配置

  • 标签背景
  • 每个标签的图片
  • 选中标签的图片
  • 每个标签按钮的背景
  • 底部偏移量。从底部获取具有偏移量的元素
  • Y 轴偏移量。从标签栏顶部获取具有偏移量的元素
  • 每个元素的自定义框架大小

不支持

  • Storyboard
  • 仅支持最多 5 个项目

工作原理

  1. 将带有 TTTabBar 的 UIViewController 子类化,它可以在 storyboard 中,TTTabBar 是 UIViewController 的子类

  2. 创建 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)
  1. 配置 TabBar
self.tabBackgroundColor = UIColor.lightGrayColor()
  1. 将元素设置到 TabBar 中。现在它最多支持 5 个
self.tabBarItems = [item, item2, item3, item4, item5]
  1. 最后,在每次更改 tabBar 时调用 updateTabBarView
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)