JBScrollingTabBarController 0.1.8

JBScrollingTabBarController 0.1.8

测试已测试
Lang语言 SwiftSwift
许可证 MIT
Released上次发布2016年11月
SwiftSwift 版本3.0
SPM支持 SPM

Jeff Breunig 维护。



  • 作者:
  • Jeff Breunig

JBScrollingTabBarController

JBScrollingTabBarController 是一个可滚动和可定制的 UITabBarController 子类,允许用户在不显示更多导航界面的情况下显示不止 5 个 TabBarItem。

要求

  • iOS 9.0+
  • Swift 3.0
  • Xcode 8.0

安装

JBScrollingTabBarController 可以通过 CocoaPods 获取。要安装它,只需将以下行添加到 Podfile 中

pod "JBScrollingTabBarController"

示例

要运行示例项目,请克隆仓库,并从 Example 目录中运行项目。

使用方法

import JBScrollingTabBarController

// Instantiate JBScrollingTabBarController.  All arguments for designated initializer are optional.

let tabBarController = JBScrollingTabBarController(maxNumberOfButtonsOnScreen: 5,
                                                       barTintColor: UIColor.white,
                                                       buttonActiveColor: UIColor.blue,
                                                       buttonInactiveColor: UIColor.lightGray,
                                                       buttonActiveFont: UIFont.boldSystemFont(ofSize: 12),
                                                       buttonInactiveFont: UIFont.systemFont(ofSize: 12))

// Assign controllers to JBScrollingTabBarController instance.

var controllers = [UINavigationController]()

let tabObjects: [TabObject] = [
    TabObject(color: UIColor.red, tabTitle: "One", viewTitle: "1", imageName: "One"),
    TabObject(color: UIColor.orange, tabTitle: "Two", viewTitle: "2", imageName: "Two"),
    TabObject(color: UIColor.yellow, tabTitle: "Three", viewTitle: "3", imageName: "Three"),
    TabObject(color: UIColor.green, tabTitle: "Four", viewTitle: "4", imageName: "Four"),
    TabObject(color: UIColor.blue, tabTitle: "Five", viewTitle: "5", imageName: "Five"),
    TabObject(color: UIColor.magenta, tabTitle: "Six", viewTitle: "6", imageName: "Six"),
    TabObject(color: UIColor.purple, tabTitle: "Seven", viewTitle: "7", imageName: "Seven")                   
]

for tabObject in tabObjects {
    let navigationController = setupNavController(tabObject: tabObject)
    controllers.append(navigationController)
}

tabBarController.scrollingTabBarViewControllers = controllers


func setupNavController(tabObject: TabObject) -> UINavigationController {
    let viewController = ViewController(backgroundTitle: tabObject.viewTitle, color: tabObject.color)
    let navController = UINavigationController(rootViewController: viewController)
    let image = UIImage(named: tabObject.imageName)
    navController.tabBarItem = UITabBarItem(title: tabObject.tabTitle, image: image, selectedImage: nil)
    return navController
}  

// Set initial selected button index.

tabBarController.index = 0 

// Assign JBScrollingTabBarController instance as the window's rootViewController in UIApplicationDelegate.application:didFinishLaunchingWithOptions

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    tabBarController.setupTabBarController()
    window?.rootViewController = tabBarController
    window?.makeKeyAndVisible()
    return true
}

JBScrollingTabBarController 公共 API

init(
    maxNumberOfButtonsOnScreen: Int, // default 5
    barTintColor: UIColor, // default UIColor(white: 0.9, alpha: 1.0)
    buttonActiveColor: UIColor, // default UIColor.blue
    buttonInactiveColor: UIColor, // default UIColor(white: 0.6, alpha: 1.0)
    buttonActiveFont: UIFont, // default UIFont.boldSystemFont(ofSize: 12)
    buttonInactiveFont: UIFont // default UIFont.systemFont(ofSize: 12)
)
var scrollingTabBarViewControllers: [UIViewController]?
var barTintColor: UIColor   
var buttonActiveColor: UIColor  
var buttonInactiveColor: UIColor
var buttonActiveFont: UIFont   
var buttonInactiveFont: UIFont 
var shouldRotateButtons: Bool // default true
var rotateButtonDuration: Double // default 0.5
var index: Int // default 0
var bounces: Bool // default true
var selectedViewController: UIViewController?    

作者

Jeff Breunig, [email protected]

许可证

JBScrollingTabBarController 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。