FlexTabBar 1.1.0

FlexTabBar 1.1.0

测试已测试
Lang语言 SwiftSwift
许可 MIT
发布上次发布2017年2月
SwiftSwift 版本3.0
SPM支持 SPM

Austin Kettner 维护。



  • Adrian Mateoaea

Flexible Tab Bar Header

灵活的标签栏是一种对标签栏的定制方法,允许您为不同的 方向/设备状态 创建不同的视图。iOS 默认的 UITabBar 很有限,而且很难为其不同的设备状态进行定制。

预览

  • 纵向(中间有一个不同类型的按钮,并且在点击时有不同的显示方式)
  • 横向(与纵向相同的标签布局)

以及 iPad

  • 纵向(中间按钮现在放置在末尾,并且具有与标签页相同的显示风格)
  • 横向(与纵向相同的标签布局,但现在它显示了标签项标题,因为现在有更多空间扩展)

添加到您的项目

要将 FlexTabBar 通过 CocoaPods 添加到项目,只需创建一个 Podfile 并添加此行

pod 'open-tab-bar'

通过运行 pod install 安装 pod

用法

1. 扩展控制器

首先将您的视图控制器从 WKTabBarController 中扩展

class ViewController: WKTabBarController {

}

2. 设置项

您可以在 viewDidLoad 函数中通过 tabBarItems 属性设置项

tabBarItems = [
  WKTabBarItem(title       : TAB_ITEM_TITLE,
               image       : NORMAL_IMAGE,
               highlighted : HIGHLIGHTED_IMAGE, (OPTIONAL)
               selected    : SELECTED_IMAGE     (OPTIONAL)
  )
]

3. 自定义项

WKTabBarController 已经实现了 WKTabBarControllerProtocol,因此您可以在您的 ViewController 中覆盖这些方法,以自定义项的外观

func tabBarController(_ controller: WKTabBarController, cellNameAtIndex index: Int) -> WKTabBarCellName
func tabBarController(_ controller: WKTabBarController, customize cell: WKBaseTabBarCell, with item: WKTabBarItem, at index: Int)

下面的行允许您返回要显示的视图控制器。如果您决定要执行不涉及显示控制器的事情,然后执行您的事情,然后 return nil

func tabBarController(_ controller: WKTabBarController, viewControllerAtIndex index: Int) -> UIViewController?

4. 自定义标签栏项

创建一个扩展 WKBaseTabBarCell 类的类

final class CustomTabBarItem: WKBaseTabBarCell {

}

在这个类中,您可以覆盖这些方法以自定义项的外观

open func set(model: WKTabBarItem) // called when setting the tab bar model
open func commonInit()             // called when initialized
open func set(highlighted: Bool)   // called when the item should change its appearance on highlighted
open func set(selected: Bool)      // called when the item should change its appearance on selected

操作完成后,请务必使用此行注册新的类。

self.register(cell: CustomTabBarItem.self, withName: "CustomTabBarItem")

现在您可以返回要显示的自定义单元格。

func tabBarController(_ controller: WKTabBarController, cellNameAtIndex index: Int) -> WKTabBarCellName {
  return "CustomTabBarItem"
}

鸣谢

Adrian Mateoaea

版权