Go to file
Martin Barreto 8784865790 rename types to make them shorter 2016-01-29 01:11:27 -03:00
Example rename types to make them shorter 2016-01-29 01:11:27 -03:00
Example.xcodeproj added Youtube, Instagram and Spotify Examples. 2016-01-28 14:54:24 -03:00
Playground.playground initial commit 2016-01-20 12:39:25 -03:00
Sources rename types to make them shorter 2016-01-29 01:11:27 -03:00
Tests initial commit 2016-01-20 12:39:25 -03:00
XLPagerTabStrip adds TwitterPagerTabStripViewController & example 2016-01-22 15:23:54 -03:00
XLPagerTabStrip.xcodeproj rename types to make them shorter 2016-01-29 01:11:27 -03:00
XLPagerTabStrip.xcworkspace initial commit 2016-01-20 12:39:25 -03:00
.gitignore initial commit 2016-01-20 12:39:25 -03:00
.travis.yml initial commit 2016-01-20 12:39:25 -03:00
CHANGELOG.md update contributing.md 2016-01-26 15:43:21 -03:00
CONTRIBUTING.md update contributing.md 2016-01-26 15:43:21 -03:00
Cartfile.private initial commit 2016-01-20 12:39:25 -03:00
LICENSE initial commit 2016-01-20 12:39:25 -03:00
README.md rename types to make them shorter 2016-01-29 01:11:27 -03:00
XLPagerTabStrip.podspec update contributing.md 2016-01-26 15:43:21 -03:00

README.md

XLPagerTabStrip

Build status Platform iOS Swift 2 compatible Carthage compatible CocoaPods compatible License: MIT

Made with ❤️ by Xmartlabs.

Android PagerTabStrip for iOS!

XLPagerTabStrip is a Container View Controller that allows us to switch easily among a collection of view controllers. Pan gesture can be used to move on to next or previous view controller. It shows a interactive indicator of the current, previous, next child view controllers.

Pager Types

The library provides 4 different ways to show the view controllers.

Button Bar

This is likely to be the most common pager type. It's used by many well known apps such as instagram, youtube, skype and many others.

Bar

This mode doesn't show a title neither a image. It only shows a bar that indicates the current view controller.

Twitter

Long time ago twitter app made use of this type of pager in the app main screen.

Segmented

This mode uses a UISegmentedControl to indicates which is the view controller being displayed.

Usage

Basically we just need to provide the list of child view controllers to show and these view controllers should provide the information (title or image) that will be shown in the associated indicator.

Let's see the steps to do this:

Choose which type of pager we want to create

Fist we should choose the type of pager we want to create, depending on our choice we will have to create a view controller that extend from one of the following controllers: TwitterPagerTabStripViewController, ButtonBarPagerTabStripViewController, SegmentedPagerTabStripViewController, BarPagerTabStripViewController.

All these build-in pager controllers extend from the base class PagerTabStripViewController. You can also make your custom pager controller by extending directly from PagerTabStripViewController in case no pager menu type fits your needs.

import XLPagerTabStrip

class MyPagerTabStripName: ButtonBarPagerTabStripViewController {
  ..
}
Connect outlets and add layout constraints

We strongly recommend to use IB to set up our page controller views.

Drag into the storyboard a UIViewController and set up its class with your pager controller (MyPagerTabStripName). Drag a UIScrollView into your view controller view and connect PagerTabStripViewController contentView outlet with the scroll view.

Depending on which type of paging view controller you are working with you may have to connect more outlets.

For BarPagerTabStripViewController we should connect barView outlet. ButtonBarPagerTabStripViewController requires us to connect buttonBarView outlet. SegmentedPagerTabStripViewController has a segmentedControl outlet, if the outlet is not connected the library try to set up the navigationItem titleView property using a UISegmentedControl. TwitterPagerTabStripViewController doesn't require us to connect any additional outlet.

The example project contains a example for each pager controller type and we can look into it to see how views were added and how outlets were connected.

Provide the view controllers that will appear embedded into the PagerTabStrip view controller

You can provide the view controllers by overriding func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] method.

override public func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  return [MyEmbeddedViewController(), MySecondEmbeddedViewController()]
}

The method above is the only method declared in PagerTabStripDataSource protocol. We don't need to explicitly conform to it since base pager class already does it.

Provide information to show in each indicator

Every UIViewController that will appear within the PagerTabStrip needs to provide either a title or an image. In order to do so they should conform to IndicatorInfoProvider by implementing func indicatorInfoForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo which provides the information required to show the PagerTabStrip menu (indicator) associated with the view controller.

class MyEmbeddedViewController: UITableViewController, IndicatorInfoProvider {

  func indicatorInfoForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
    return IndicatorInfo(title: "My Child title")
  }
}

That's it! We're done! 🍻🍻

Customization

Requirements

  • iOS 8.0+
  • Xcode 7.2+

Getting involved

  • If you want to contribute please feel free to submit pull requests.
  • If you have a feature request please open an issue.
  • If you found a bug or need help please check older issues, FAQ and threads on StackOverflow (Tag 'XLPagerTabStrip') before submitting an issue.

Before contribute check the CONTRIBUTING file for more info.

If you use XLPagerTabStrip in your app We would love to hear about it! Drop us a line on twitter.

Examples

Follow these 3 steps to run Example project: Clone XLPagerTabStrip repository, open XLPagerTabStrip workspace and run the Example project.

You can also experiment and learn with the XLPagerTabStrip Playground which is contained in XLPagerTabStrip.workspace.

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects.

To install XLPagerTabStrip, simply add the following line to your Podfile:

pod 'XLPagerTabStrip', '~> 4.0'

Carthage

Carthage is a simple, decentralized dependency manager for Cocoa.

To install XLPagerTabStrip, simply add the following line to your Cartfile:

github "xmartlabs/XLPagerTabStrip" ~> 4.0

FAQ

How to change the visible child view controller programmatically

XLPagerTabStripViewController provides the following methods to programmatically change the visible child view controller:

func moveToViewControllerAtIndex(index: Int)
func moveToViewControllerAtIndex(index: Int, animated: Bool)
func moveToViewController(viewController: UIViewController)
func moveToViewController(viewController: UIViewController, animated: Bool)

Author

Change Log

This can be found in the CHANGELOG.md file.