SwiftPagingTabView 0.1.7

SwiftPagingTabView 0.1.7

Maintained by dragonetail.



 
Depends on:
PureLayout~> 3.1.4
SwiftBaseBootstrap>= 0
 

  • By
  • dragonetail

SwiftPagingTabView

Version Platform Swift Version Swift Version License

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • Swift 4.2
  • iOS 9.0+
  • Xcode 10.1

Installation

SwiftPagingTabView is available through CocoaPods. To install it, simply add the following line to your Podfile:

platform :ios, '11.0'
use_frameworks!
pod 'SwiftPagingTabView'

To get the full benefits import SwiftPagingTabView wherever you import UIKit

import UIKit
import SwiftPagingTabView

Usage example

Programmatically

import UIKit
import SwiftPagingTabView

class ViewController: UIViewController {

    public lazy var pagingTabView: PagingTabView = {
        let pagingTabView: PagingTabView = PagingTabView()
        pagingTabView.config = PagingTabViewConfig()
        pagingTabView.delegate = self
        pagingTabView.datasource = self

        return pagingTabView
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.addSubview(pagingTabView)

        pagingTabView.reloadAndSetup()
    }

extension ViewController: PagingTabViewDelegate {
    func pagingTabView(pagingTabView: PagingTabView, toIndex: Int) {
        print("Switch to paging tab view: \(toIndex)")
    }

    func reconfigure(pagingTabView: PagingTabView) {
        pagingTabView.tabButtons.forEach { (tabButton) in
            tabButton.configure(config: TabButtonConfig())
        }
    }
}
extension ViewController: PagingTabViewDataSource {
    func segments(pagingTabView: PagingTabView) -> Int {
        return 4
    }

    func tabTitle(pagingTabView: PagingTabView, index: Int) -> (image: UIImage?, title: String?) {
        if commandView.isEnableImageTitle {
            return (image: UIImage(named: "menu"),
                    title: "TAB标签_" + String(index))
        } else {
            return (image: nil,
                    title: "TAB标签_" + String(index))
        }
    }

    func tabView(pagingTabView: PagingTabView, index: Int) -> UIView {
        if index == 0 {
            return commandView
        } else {
            let view = UILabel()
            view.backgroundColor = UIColor.white
            view.text = "View " + String(index)
            view.textAlignment = .center
            return view
        }
    }
}

Author

dragonetail, [email protected]

License

SwiftPagingTabView is available under the MIT license. See the LICENSE file for more info.