Git Product home page Git Product logo

lzviewpager's Introduction

⭐️ Features

  • Super easy to implement page view controller with indicator bar.
  • Simplistic, yet highly extensive customisation.
  • Full support for custom components.
  • Built on a powerful and informative page view controller.
  • Header scrollable, if the width of buttons is larger than the width of the current view.

📋 Requirements

LZViewPager requires iOS 9, Swift 4

📲 Installation

CocoaPods

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

pod 'LZViewPager', '~> 1.0.4'

And run pod install.

If your pod install doesn't work properly, maybe your pod repository needs to be updated. You can try

pod repo update

and then run

pod install

Carthage

LZViewPager is also available through Carthage. Simply install carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

Carthage dependency

Since this project depends on SnapKit(A Swift Autolayout DSL for iOS & OS X). You can add LZViewPager to your Cartfile like this:

github "SnapKit/SnapKit" ~> 4.0.0
github "ladmini/LZViewPager" ~> 1.0.4

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate LZViewPager into your project manually. Just copy the following 3 files into your project.

  1. LZViewPager.swift
  2. LZViewPagerHeader.swift
  3. LZViewPagerContent.swift

🚀 Usage

The Basics

  1. Create a ViewController and provide a LZViewPagerDelegate, LZViewPagerDataSource

  2. Drag a UIView into ViewVontroller's view and set it's type to LZViewPager, then set an outlet variable as "viewPager"

  1. Set the items you want to display

  2. Set the hostController to self

  3. viewPager.reload()

class ViewController: BaseViewController, LZViewPagerDelegate, LZViewPagerDataSource {
    @IBOutlet weak var viewPager: LZViewPager!
    private var subControllers:[UIViewController] = []
    override func viewDidLoad() {
        super.viewDidLoad()
        viewPager.dataSource = self
        viewPager.delegate = self
        viewPager.hostController = self
        let vc1 = UIViewController.createFromNib(storyBoardId: "ContentViewController1")!
        vc1.title = "Title1"
        let vc2 = UIViewController.createFromNib(storyBoardId: "ContentViewController2")!
        vc2.title = "Title2"
        let vc3 = UIViewController.createFromNib(storyBoardId: "ContentViewController3")!
        vc3.title = "Title3"
        let vc4 = UIViewController.createFromNib(storyBoardId: "ContentViewController4")!
        vc4.title = "Title4"
        subControllers = [vc1, vc2, vc3, vc4]
        viewPager.reload()
    }
}
  1. Implement LZViewPagerDataSource.
    func numberOfItems() -> Int {
        return self.subControllers.count
    }
    
    func controller(at index: Int) -> UIViewController {
        return subControllers[index]
    }
    
    func button(at index: Int) -> UIButton {
        //Customize your button styles here
        let button = UIButton()
        button.setTitleColor(UIColor.black, for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        return button
    }
  1. All done! 🎉

Customization

You can customize you button styles in datasource method "func button(at index: Int) -> UIButton" you can also customize other styles by implementing other datasource methods example:

func heightForHeader() -> CGFloat
func backgroundColorForHeader() -> UIColor
func heightForIndicator(at index: Int) -> CGFloat
func colorForIndicator(at index: Int) -> UIColor
func shouldShowIndicator() -> Bool
func widthForButton(at index: Int) -> CGFloat
func widthForIndicator(at index: Int) -> CGFloat
func buttonsAligment() -> ButtonsAlignment
func shouldEnableSwipeable() -> Bool

Delegate

Implementing delegate methods if needed

func didSelectButton(at index: Int)
func willTransition(to index: Int)
func didTransition(to index: Int)

Instance methods for LZViewPager

When your datasource changed you should call reload() method to refresh. If you want to locating to some page programming you can call select(index: Int, animated: Bool) method, It is important to note that animated is an optional parameter in order to be compatible with the previous versions. If you do not specify animated, it is true by default.

func reload()
public func select(index: Int, animated: Bool = true)

Instance property for LZViewPager

public var currentIndex: Int?

How to run this demo

  1. Clone this repository
  2. Execute carthage update
  3. Build and Run

⚠️ Troubleshooting

If you are encountering issues with LZViewPager, please raise an issue.

👨🏻‍💻 About

❤️ Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ladmini/LZViewPager.

👮🏻‍♂️ License

The library is available as open source under the terms of the MIT License.

lzviewpager's People

Contributors

tobaloidee avatar ladmini avatar

Stargazers

MohsinAli avatar

Watchers

MohsinAli avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.