测试已测试 | ✗ |
Lang语言 | SwiftSwift |
许可 | MIT |
发布上次发布 | 2017年2月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Austin Kettner 维护。
灵活的标签栏是一种对标签栏的定制方法,允许您为不同的 方向/设备 或 状态 创建不同的视图。iOS 默认的 UITabBar
很有限,而且很难为其不同的设备状态进行定制。
要将 FlexTabBar 通过 CocoaPods 添加到项目,只需创建一个 Podfile
并添加此行
pod 'open-tab-bar'
通过运行 pod install
安装 pod
首先将您的视图控制器从 WKTabBarController
中扩展
class ViewController: WKTabBarController {
}
您可以在 viewDidLoad
函数中通过 tabBarItems
属性设置项
tabBarItems = [
WKTabBarItem(title : TAB_ITEM_TITLE,
image : NORMAL_IMAGE,
highlighted : HIGHLIGHTED_IMAGE, (OPTIONAL)
selected : SELECTED_IMAGE (OPTIONAL)
)
]
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?
创建一个扩展 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"
}