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.
As you see in the images above the library provides many ways to show the PagerTabStrip menu.
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) to show in the associated indicator.
Let's see the steps to do this:
Fist step is choose how we want to show our pager step controller, it must extend from any 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 fromPagerTabStripViewController
in case no pager menu type fits your needs.
import XLPagerTabStrip
class MyPagerTabStripName: ButtonBarPagerTabStripViewController {
..
}
We strongly recommend to use IB to set up your 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
you should connect barView
outlet.
For ButtonBarPagerTabStripViewController
you should connect buttonBarView
outlet.
For SegmentedPagerTabStripViewController
you should connect segmentedControl
outlet.
TwitterPagerTabStripViewController
doesn't require to connect any additional outlet.
The example project contains a example for each pager controller type and you can look into it to see how views were added and how outlets were connected.
You can provide the view controllers by overriding func childViewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController]
method.
override public func childViewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
return [MyEmbeddedViewController(), MySecondEmbeddedViewController()]
}
The method above is the only method contained in
PagerTabStripViewControllerDataSource
. We don't need to explicitly conform to it since base pager class already does it.
Every UIViewController that will appear in the PagerTabStrip controller should conforms to PagerTabStripChildItem
. The only method this protocol requires to implement is func childHeaderForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> ChildItemInfo
which provides the information required to show the PagerTabStrip menu (indicator) associated with the view controller.
class MyEmbeddedViewController: UITableViewController, PagerTabStripChildItem {
func childInfoForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> ChildItemInfo {
return ChildItemInfo(title: "My Child title")
}
}
That's it! We're done! 🍻🍻
- iOS 8.0+
- Xcode 7.2+
- 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.
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.
CocoaPods is a dependency manager for Cocoa projects.
To install XLPagerTabStrip, simply add the following line to your Podfile:
pod 'XLPagerTabStrip', '~> 4.0'
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
This can be found in the CHANGELOG.md file.