EVTopTabBar 3.0.0

EVTopTabBar 3.0.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2021年4月
SPM支持 SPM

Eric Vennaro 维护。



  • 作者
  • Eric Vennaro

EVTopTabBar




关于

EVTopTabBar 是一个自定义的 UIPageViewController,其中页面控制器位于顶部。它目前支持最多 4 个标签。

Screenshot1

使用方法

要运行示例项目,克隆仓库,然后在 Example 目录中运行 pod install

要求

  • Swift 3.0+
  • iOS 9.0+

安装

EVTopTabBar 可通过 CocoaPods 使用。要安装它,只需将以下行添加到 Podfile 中

pod "EVTopTabBar"

另外包括

use_frameworks!

文档

阅读 文档。由 jazzy 生成

入门

import EVTopTabBar

实现 EVTabBar 协议并遵守它(示例项目有详细的实现)。为了遵守协议,请声明以下内容

var pageController = UIPageViewController(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: nil)
//need to instantiate the topTabBar itself, later we will implement the delegate method
//enum .two, .three, .four correspond to the number of tabs you wish to display
var topTabBar: EVPageViewTopTabBar = EVPageViewTopTabBar(for: .four)
//array of view controllers that will be controlled by the page view controller
var subviewControllers: [UIViewController] = []
//image from the sample project can use any UIImage you want, this shadow is what is displayed under the tab bar.
var shadowView = UIImageView(image: UIImage(imageLiteral: "filter-background-image"))

现在在您的视图控制器中实现 EVPageViewTopTabBarDelegate 方法 willSelectViewControllerAtIndex。此方法允许视图控制器切换,并提供空间执行其他操作。

extension ViewController: EVPageViewTopTabBarDelegate {
    //delegate method
    func willSelectViewControllerAtIndex(index: Int, direction: UIPageViewControllerNavigationDirection) {
        //required line that changes the displayed view controller
        pageController.setViewControllers([self.subviewControllers[index]], direction: direction, animated: true, completion: nil)
        //add whatever code you wish to occur on the transition!
    }
}

接下来,将需要调用 setupPageView()setupConstraints() 方法以设置页面布局。您可以通过覆盖这两个方法来创建更自定义的应用程序。

最后,您将需要设置之前声明的 topTabBar

//attributes of the topTabBar you can set
topTabBar.fontColors = (selectedColor: UIColor.grayColor(), unselectedColor: UIColor.lightGrayColor())
topTabBar.rightButtonText = "Events"
topTabBar.leftButtonText = "Contacts"
topTabBar.labelFont = UIFont(name: ".SFUIText-Regular", size: 11)!
topTabBar.indicatorViewColor = UIColor.blueColor()
topTabBar.backgroundColor = UIColor.whiteColor()
//ensure you set the topTabBar's delegate
topTabBar.delegate = self
//add view controllers you wish to display
let firstVC = FirstViewController(nibName:"FirstViewController", bundle: nil)
let secondVC = SecondViewController(nibName:"SecondViewController", bundle: nil)
subviewControllers = [firstVC, secondVC]
setupPageView()
setupConstraints()

项目描述

EVTabBar 协议

方法

  • setupPageView() 设置视图控制器中的 UI,包括 UIPageViewController、shadowView 以及要在页面视图中显示的视图控制器。
  • setupConstraints() 设置视图控制器的初始约束

EVPageViewTopTabBar

方法

  • willSelectViewControllerAtIndex(index: Int, direction: UIPageViewControllerNavigationDirection) 控制页面视图内部的视图控制器切换,并提供空间在转换时执行其他操作。

未来功能

  • 对 shadow view 的更多灵活性

作者

Eric Vennaro,[email protected]博客

许可证

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

版权 © 2016 年至现在 Eric Vennaro。