LKTabBarController 1.0.0

LKTabBarController 1.0.0

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

Abraham Done 维护。



  • Abraham Done

LKTabBarController

Circle CI

一个简单的 Swift 标签栏控制器

特性

  • 简单的协议实现以创建定制的标签按钮
  • 标签按钮可以放置在任何位置
  • 快速链接按钮和视图
  • 轻松控制视图切换

基本用法

按钮必须实现该协议

public protocol LKTabBarButtonView {
    var selected: Bool { get set }
    var index: Int { get set }
    var delegate: LKButtonBarIndexDelegate? { get set }
}

按钮的任何其他自定义都是设计决定。

按钮将通过代理控制标签栏

public protocol LKButtonBarIndexDelegate {
    func buttonTapped(index: Int)
    var index: Int { get set }
}

需要将该按钮与视图控制器配对,如下所示

public typealias TabButtonViewPair = (button: LKTabBarButtonView, viewController: UIViewController)

将传递一个 TabButtonViewPair 数组到 LKTabBarController 的初始化器,就这样。

详细用法

只要它符合 LKTabBarButtonBarView 协议,按钮可以在任何视图中创建。视图中也应有按钮或手势识别器,用于某种交互,但视图可以具有图像、文本等。

这是一个示例

class ButtonView: UIView, LKTabBarButtonView {

    // required elements

    // The button doesn't do anything to set these, just have them available for the tab bar to set up
    // The delegate is set when it is set as a button/view pair in the LKTabBarController's init function
    var delegate: LKButtonBarIndexDelegate?
    // The index is also set up when it is initialized
    var index: Int = 0

    // The actions that can happen when the button's state is changed by the LKTabBarController.
    var selected: Bool = false {
        didSet {
            if selected {
                button.setTitleColor(self.color, forState: .Normal)
                button.enabled = false
                colorBar.backgroundColor = self.color
            } else {
                button.setTitleColor(UIColor.grayColor(), forState: .Normal)
                button.enabled = true
                colorBar.backgroundColor = UIColor.grayColor()
            }
        }
    }

    // user elements    
    @IBAction func buttonTapped() {

        // This is the action that will set the LKTabBarController's index and will change the view
        delegate?.buttonTapped(index)
    }
    ... 
}

按钮将与视图控制器配对

let buttonViewPairs: [LKTabBarController.TabButtonViewPair] = []
let viewController = SomeViewController()
let button = ButtonView()

buttonViewPairs.append((button, viewController))

当所有视图和按钮设置完毕后,才能初始化 LKTabBarController

let tabController = LKTabBarController(buttonPairs: buttonViewPairs, parientView: self, containerView: contentView)

然后,LKTabBarController 将负责其提供容器视图内的视图切换

按钮的实际位置和外观完全取决于与项目兼容的设计。

测试

安装

LKTabBarController 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile 中

pod "LKTabBarController"

问题、问题和贡献

有问题的,或者想要请求一个功能?在 github 上创建一个问题。

想要贡献?将自己添加到作者列表中,并创建一个 pull request。

作者

Abraham Done,[email protected]

许可证

LKTabBarController受MIT许可证的保护。更多信息,请参阅LICENSE文件。