diff --git a/Example/Example/BarExampleViewController.swift b/Example/Example/BarExampleViewController.swift index 8839808..b9397f5 100644 --- a/Example/Example/BarExampleViewController.swift +++ b/Example/Example/BarExampleViewController.swift @@ -43,7 +43,7 @@ class BarExampleViewController: BarPagerTabStripViewController { // MARK: - PagerTabStripViewControllerDataSource - override func childViewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { + override func viewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: "Table View") let child_2 = ChildExampleViewController(itemInfo: "View") diff --git a/Example/Example/ButtonBarExampleViewController.swift b/Example/Example/ButtonBarExampleViewController.swift index 62c17ff..d884a2d 100644 --- a/Example/Example/ButtonBarExampleViewController.swift +++ b/Example/Example/ButtonBarExampleViewController.swift @@ -38,7 +38,7 @@ class ButtonBarExampleViewController: ButtonBarPagerTabStripViewController { // MARK: - PagerTabStripVIewControllerDataSource - override func childViewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { + override func viewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: "Table View") let child_2 = ChildExampleViewController(itemInfo: "View") let child_3 = TableChildExampleViewController(style: .Grouped, itemInfo: "Table View 2") diff --git a/Example/Example/ChildControllers/ChildExampleViewController.swift b/Example/Example/ChildControllers/ChildExampleViewController.swift index 9b02354..498bda4 100644 --- a/Example/Example/ChildControllers/ChildExampleViewController.swift +++ b/Example/Example/ChildControllers/ChildExampleViewController.swift @@ -25,11 +25,11 @@ import Foundation import XLPagerTabStrip -class ChildExampleViewController: UIViewController, PagerTabStripChildItem { +class ChildExampleViewController: UIViewController, IndicatorInfoProvider { - var itemInfo: ChildItemInfo = "View" + var itemInfo: IndicatorInfo = "View" - init(itemInfo: ChildItemInfo) { + init(itemInfo: IndicatorInfo) { self.itemInfo = itemInfo super.init(nibName: nil, bundle: nil) } @@ -52,9 +52,9 @@ class ChildExampleViewController: UIViewController, PagerTabStripChildItem { view.addConstraint(NSLayoutConstraint(item: label, attribute: .CenterY, relatedBy: .Equal, toItem: view, attribute: .CenterY, multiplier: 1, constant: -50)) } - // MARK: - PagerTabStripChildItem + // MARK: - IndicatorInfoProvider - func childInfoForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> ChildItemInfo { + func infoForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo { return itemInfo } } diff --git a/Example/Example/ChildControllers/TableChildExampleViewController.swift b/Example/Example/ChildControllers/TableChildExampleViewController.swift index 939f83a..d20aad4 100644 --- a/Example/Example/ChildControllers/TableChildExampleViewController.swift +++ b/Example/Example/ChildControllers/TableChildExampleViewController.swift @@ -25,13 +25,13 @@ import Foundation import XLPagerTabStrip -class TableChildExampleViewController: UITableViewController, PagerTabStripChildItem { +class TableChildExampleViewController: UITableViewController, IndicatorInfoProvider { let cellIdentifier = "postCell" var blackTheme = false - var itemInfo = ChildItemInfo(title: "View") + var itemInfo = IndicatorInfo(title: "View") - init(style: UITableViewStyle, itemInfo: ChildItemInfo) { + init(style: UITableViewStyle, itemInfo: IndicatorInfo) { self.itemInfo = itemInfo super.init(style: style) } @@ -77,9 +77,9 @@ class TableChildExampleViewController: UITableViewController, PagerTabStripChild return cell } - // MARK: - PagerTabStripChildItem - - func childInfoForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> ChildItemInfo { + // MARK: - IndicatorInfoProvider + + func infoForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo { return itemInfo } } diff --git a/Example/Example/Instagram/InstagramExampleViewController.swift b/Example/Example/Instagram/InstagramExampleViewController.swift index 3d0e874..08032a2 100644 --- a/Example/Example/Instagram/InstagramExampleViewController.swift +++ b/Example/Example/Instagram/InstagramExampleViewController.swift @@ -54,7 +54,7 @@ class InstagramExampleViewController: ButtonBarPagerTabStripViewController { // MARK: - PagerTabStripVIewControllerDataSource - override func childViewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { + override func viewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: "FOLLOWING") let child_2 = ChildExampleViewController(itemInfo: "YOU") return [child_1, child_2] diff --git a/Example/Example/NavButtonBarExampleViewController.swift b/Example/Example/NavButtonBarExampleViewController.swift index 1be5ffc..3a73f4f 100644 --- a/Example/Example/NavButtonBarExampleViewController.swift +++ b/Example/Example/NavButtonBarExampleViewController.swift @@ -59,7 +59,7 @@ class NavButtonBarExampleViewController: ButtonBarPagerTabStripViewController { // MARK: - PagerTabStripViewControllerDataSource - override func childViewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { + override func viewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: "Table View") let child_2 = ChildExampleViewController(itemInfo: "View") let child_3 = TableChildExampleViewController(style: .Grouped, itemInfo: "Table View 2") @@ -97,8 +97,8 @@ class NavButtonBarExampleViewController: ButtonBarPagerTabStripViewController { super.reloadPagerTabStripView() } - override func configureCell(cell: ButtonBarViewCell, childInfo: ChildItemInfo) { - super.configureCell(cell, childInfo: childInfo) + override func configureCell(cell: ButtonBarViewCell, indicatorInfo: IndicatorInfo) { + super.configureCell(cell, indicatorInfo: indicatorInfo) cell.backgroundColor = .clearColor() } } diff --git a/Example/Example/SegmentedExampleViewController.swift b/Example/Example/SegmentedExampleViewController.swift index b07e33d..761f57a 100644 --- a/Example/Example/SegmentedExampleViewController.swift +++ b/Example/Example/SegmentedExampleViewController.swift @@ -37,7 +37,7 @@ class SegmentedExampleViewController: SegmentedPagerTabStripViewController { // MARK: - PagerTabStripViewControllerDataSource - override func childViewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { + override func viewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: "Table View") let child_2 = ChildExampleViewController(itemInfo: "View") let child_3 = TableChildExampleViewController(style: .Grouped, itemInfo: "Table View 2") diff --git a/Example/Example/Spotify/SpotifyExampleViewController.swift b/Example/Example/Spotify/SpotifyExampleViewController.swift index 0e5e710..2e7619d 100644 --- a/Example/Example/Spotify/SpotifyExampleViewController.swift +++ b/Example/Example/Spotify/SpotifyExampleViewController.swift @@ -57,10 +57,10 @@ public class SpotifyExampleViewController: ButtonBarPagerTabStripViewController // MARK: - PagerTabStripVIewControllerDataSource - public override func childViewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { - let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: ChildItemInfo(title: "FRIENDS")) + public override func viewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { + let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: IndicatorInfo(title: "FRIENDS")) child_1.blackTheme = true - let child_2 = TableChildExampleViewController(style: .Plain, itemInfo: ChildItemInfo(title: "FEATURED")) + let child_2 = TableChildExampleViewController(style: .Plain, itemInfo: IndicatorInfo(title: "FEATURED")) child_2.blackTheme = true return [child_1, child_2] } diff --git a/Example/Example/TwitterExampleViewController.swift b/Example/Example/TwitterExampleViewController.swift index 6eaa76f..3b1a338 100644 --- a/Example/Example/TwitterExampleViewController.swift +++ b/Example/Example/TwitterExampleViewController.swift @@ -28,7 +28,7 @@ import XLPagerTabStrip class TwitterExampleViewController: TwitterPagerTabStripViewController { var isReload = false - override func childViewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { + override func viewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: "TableView") let child_2 = ChildExampleViewController(itemInfo: "View") diff --git a/Example/Example/Youtube/YoutubeExampleViewController.swift b/Example/Example/Youtube/YoutubeExampleViewController.swift index 0549363..2c81131 100644 --- a/Example/Example/Youtube/YoutubeExampleViewController.swift +++ b/Example/Example/Youtube/YoutubeExampleViewController.swift @@ -38,7 +38,7 @@ class YoutubeExampleViewController: BaseButtonBarPagerTabStripViewController CGFloat in + buttonBarItemSpec = ButtonBarItemSpec.NibFile(nibName: "YoutubeIconCell", bundle: NSBundle(forClass: YoutubeIconCell.self), width: { (cell: IndicatorInfo) -> CGFloat in return 55.0 }) } @@ -72,26 +72,26 @@ class YoutubeExampleViewController: BaseButtonBarPagerTabStripViewController [UIViewController] { - let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: ChildItemInfo(title: " HOME", image: UIImage(named: "home"))) - let child_2 = TableChildExampleViewController(style: .Plain, itemInfo: ChildItemInfo(title: " TRENDING", image: UIImage(named: "trending"))) - let child_3 = ChildExampleViewController(itemInfo: ChildItemInfo(title: " ACCOUNT", image: UIImage(named: "profile"))) + override func viewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { + let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: IndicatorInfo(title: " HOME", image: UIImage(named: "home"))) + let child_2 = TableChildExampleViewController(style: .Plain, itemInfo: IndicatorInfo(title: " TRENDING", image: UIImage(named: "trending"))) + let child_3 = ChildExampleViewController(itemInfo: IndicatorInfo(title: " ACCOUNT", image: UIImage(named: "profile"))) return [child_1, child_2, child_3] } - override func configureCell(cell: YoutubeIconCell, childInfo: ChildItemInfo) { - cell.iconImage.image = childInfo.image?.imageWithRenderingMode(.AlwaysTemplate) + override func configureCell(cell: YoutubeIconCell, indicatorInfo: IndicatorInfo) { + cell.iconImage.image = indicatorInfo.image?.imageWithRenderingMode(.AlwaysTemplate) } override func pagerTabStripViewController(pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) throws { try super.pagerTabStripViewController(pagerTabStripViewController, updateIndicatorFromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: progressPercentage, indexWasChanged: indexWasChanged) if indexWasChanged && toIndex > -1 && toIndex < viewControllers.count { - let child = viewControllers[toIndex] as! PagerTabStripChildItem + let child = viewControllers[toIndex] as! IndicatorInfoProvider UIView.performWithoutAnimation({ [weak self] () -> Void in guard let me = self else { return } - me.navigationItem.leftBarButtonItem?.title = child.childInfoForPagerTabStripViewController(me).title + me.navigationItem.leftBarButtonItem?.title = child.infoForPagerTabStripViewController(me).title }) } } diff --git a/Example/PagerSlidingTabStrip.gif b/Example/PagerSlidingTabStrip.gif deleted file mode 100755 index 75af241..0000000 Binary files a/Example/PagerSlidingTabStrip.gif and /dev/null differ diff --git a/Example/bar.gif b/Example/bar.gif new file mode 100644 index 0000000..01f0de2 Binary files /dev/null and b/Example/bar.gif differ diff --git a/Example/barButton.gif b/Example/barButton.gif new file mode 100644 index 0000000..d253781 Binary files /dev/null and b/Example/barButton.gif differ diff --git a/Example/navBarButton.gif b/Example/navBarButton.gif new file mode 100644 index 0000000..0ad6d6b Binary files /dev/null and b/Example/navBarButton.gif differ diff --git a/Example/segmented.gif b/Example/segmented.gif new file mode 100644 index 0000000..11923b1 Binary files /dev/null and b/Example/segmented.gif differ diff --git a/Example/twitter.gif b/Example/twitter.gif new file mode 100644 index 0000000..a2ee71a Binary files /dev/null and b/Example/twitter.gif differ diff --git a/README.md b/README.md index 18de12f..8f6ec97 100644 --- a/README.md +++ b/README.md @@ -24,18 +24,44 @@ Android [PagerTabStrip](http://developer.android.com/reference/android/support/v -The library provides many ways to show the PagerTabStrip menu. +## 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) to show in the associated indicator. +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 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`. +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. @@ -50,36 +76,34 @@ class MyPagerTabStripName: ButtonBarPagerTabStripViewController { ##### Connect outlets and add layout constraints -We strongly recommend to use IB to set up your page controller views. +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` 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. +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 using a `UIsegmentedControl`. `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. +> 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 view controllers that will appear embedded into the PagerTabStrip view controller +##### Provide the view controllers that will appear embedded into the PagerTabStrip view controller -You can provide the view controllers by overriding `func childViewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController]` method. +You can provide the view controllers by overriding `func viewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController]` method. ```swift -override public func childViewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { +override public func viewControllersForPagerTabStripViewController(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. +> The method above is the only method declared in `PagerTabStripViewControllerDataSource` 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 in the PagerTabStrip controller should conforms to `PagerTabStripChildItem`. The only method this protocol requires to implement is `func childHeaderForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> ChildItemInfo` +Every UIViewController that will appear within the PagerTabStrip controller needs to provide either a title or an image. +In order to do so they should conform to `PagerTabStripChildItem` by implementing `func childHeaderForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> ChildItemInfo` which provides the information required to show the PagerTabStrip menu (indicator) associated with the view controller. ```swift diff --git a/Sources/BaseButtonBarPagerTabStripViewController.swift b/Sources/BaseButtonBarPagerTabStripViewController.swift index 6d3c0db..7681b09 100644 --- a/Sources/BaseButtonBarPagerTabStripViewController.swift +++ b/Sources/BaseButtonBarPagerTabStripViewController.swift @@ -230,10 +230,10 @@ public class BaseButtonBarPagerTabStripViewController { - case NibFile(nibName: String, bundle: NSBundle?, width:((ChildItemInfo)-> CGFloat)) - case CellClass(width:((ChildItemInfo)-> CGFloat)) + case NibFile(nibName: String, bundle: NSBundle?, width:((IndicatorInfo)-> CGFloat)) + case CellClass(width:((IndicatorInfo)-> CGFloat)) - public var weight: ((ChildItemInfo) -> CGFloat) { + public var weight: ((IndicatorInfo) -> CGFloat) { switch self { case .CellClass(let widthCallback): return widthCallback @@ -265,22 +265,22 @@ public class ButtonBarPagerTabStripViewController: PagerTabStripViewController, guard let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as? ButtonBarViewCell else { fatalError("UICollectionViewCell should be or extend from ButtonBarViewCell") } - let childController = viewControllers[indexPath.item] as! PagerTabStripChildItem - let childInfo = childController.childInfoForPagerTabStripViewController(self) + let childController = viewControllers[indexPath.item] as! IndicatorInfoProvider + let indicatorInfo = childController.infoForPagerTabStripViewController(self) - cell.label.text = childInfo.title + cell.label.text = indicatorInfo.title cell.label.font = settings.style.buttonBarItemFont ?? cell.label.font cell.label.textColor = settings.style.buttonBarItemTitleColor ?? cell.label.textColor cell.contentView.backgroundColor = settings.style.buttonBarItemBackgroundColor ?? cell.contentView.backgroundColor cell.backgroundColor = settings.style.buttonBarItemBackgroundColor ?? cell.backgroundColor - if let image = childInfo.image { + if let image = indicatorInfo.image { cell.imageView.image = image } - if let highlightedImage = childInfo.highlightedImage { + if let highlightedImage = indicatorInfo.highlightedImage { cell.imageView.highlightedImage = highlightedImage } - configureCell(cell, childInfo: childInfo) + configureCell(cell, indicatorInfo: indicatorInfo) if pagerBehaviour.isProgressiveIndicator { if let changeCurrentIndexProgressive = changeCurrentIndexProgressive { @@ -304,7 +304,7 @@ public class ButtonBarPagerTabStripViewController: PagerTabStripViewController, shouldUpdateButtonBarView = true } - public func configureCell(cell: ButtonBarViewCell, childInfo: ChildItemInfo){ + public func configureCell(cell: ButtonBarViewCell, indicatorInfo: IndicatorInfo){ } private func calculateWidths() -> [CGFloat] { @@ -315,15 +315,15 @@ public class ButtonBarPagerTabStripViewController: PagerTabStripViewController, var collectionViewContentWidth: CGFloat = 0 for viewController in self.viewControllers { - let childController = viewController as! PagerTabStripChildItem - let childInfo = childController.childInfoForPagerTabStripViewController(self) + let childController = viewController as! IndicatorInfoProvider + let indicatorInfo = childController.infoForPagerTabStripViewController(self) switch buttonBarItemSpec { case .CellClass(let widthCallback): - let width = widthCallback(childInfo) + let width = widthCallback(indicatorInfo) minimumCellWidths.append(width) collectionViewContentWidth += width case .NibFile(_, _, let widthCallback): - let width = widthCallback(childInfo) + let width = widthCallback(indicatorInfo) minimumCellWidths.append(width) collectionViewContentWidth += width } diff --git a/Sources/ChildItemInfo.swift b/Sources/ChildItemInfo.swift index cbde1d2..16c9236 100644 --- a/Sources/ChildItemInfo.swift +++ b/Sources/ChildItemInfo.swift @@ -1,4 +1,4 @@ -// ChildItemInfo.swift +// IndicatorInfo.swift // XLPagerTabStrip ( https://github.com/xmartlabs/XLPagerTabStrip ) // // Copyright (c) 2016 Xmartlabs ( http://xmartlabs.com ) @@ -24,7 +24,7 @@ import Foundation -public struct ChildItemInfo { +public struct IndicatorInfo { public var title: String public var image: UIImage? @@ -46,7 +46,7 @@ public struct ChildItemInfo { } -extension ChildItemInfo : StringLiteralConvertible { +extension IndicatorInfo : StringLiteralConvertible { public init(stringLiteral value: String){ title = value diff --git a/Sources/PagerTabStripOptions.swift b/Sources/PagerTabStripBehaviour.swift similarity index 74% rename from Sources/PagerTabStripOptions.swift rename to Sources/PagerTabStripBehaviour.swift index 89aaa15..44f8310 100644 --- a/Sources/PagerTabStripOptions.swift +++ b/Sources/PagerTabStripBehaviour.swift @@ -24,23 +24,8 @@ import Foundation -//public struct PagerTabStripOptions : OptionSetType { -// -// private enum PagerTabStripOption : Int { -// case SkipIntermediateViewControllers = 1, IsProgressiveIndicator = 2, IsElasticIndicatorLimit = 4 -// } -// -// public let rawValue: Int -// public init(rawValue: Int) { self.rawValue = rawValue } -// private init(_ option:PagerTabStripOption){ self.rawValue = option.rawValue } -// -// public static let SkipIntermediateViewControllers = PagerTabStripOptions(.SkipIntermediateViewControllers) -// public static let IsProgressiveIndicator = PagerTabStripOptions(.IsProgressiveIndicator) -// public static let IsElasticIndicatorLimit = PagerTabStripOptions(.IsElasticIndicatorLimit) -// -//} - public enum PagerTabStripBehaviour { + case Common(skipIntermediteViewControllers: Bool) case Progressive(skipIntermediteViewControllers: Bool, elasticIndicatorLimit: Bool) diff --git a/Sources/PagerTabStripError.swift b/Sources/PagerTabStripError.swift index b299977..9e45688 100644 --- a/Sources/PagerTabStripError.swift +++ b/Sources/PagerTabStripError.swift @@ -26,7 +26,7 @@ import Foundation public enum PagerTabStripError: ErrorType { case DataSourceMustNotBeNil - case ChildViewControllerMustConformToPagerTabStripChildItem + case ChildViewControllerMustConformToInfoProvider case CurrentIndexIsGreaterThanChildsCount case PagerTabStripChildViewControllersMustContainAtLeastOneViewController case ViewControllerNotContainedInPagerTabStripChildViewControllers diff --git a/Sources/PagerTabStripViewController.swift b/Sources/PagerTabStripViewController.swift index e9d7a06..c01274f 100644 --- a/Sources/PagerTabStripViewController.swift +++ b/Sources/PagerTabStripViewController.swift @@ -28,9 +28,9 @@ import Foundation // MARK: Protocols -public protocol PagerTabStripChildItem { +public protocol IndicatorInfoProvider { - func childInfoForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> ChildItemInfo + func infoForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo } public protocol PagerTabStripViewControllerDelegate: class { @@ -45,7 +45,7 @@ public protocol PagerTabStripViewControllerIsProgressiveDelegate : PagerTabStrip public protocol PagerTabStripViewControllerDataSource: class { - func childViewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] + func viewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] } @@ -158,8 +158,8 @@ public class PagerTabStripViewController: UIViewController, UIScrollViewDelegate //MARK: - PagerTabStripViewControllerDataSource - public func childViewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { - assertionFailure("Sub-class must implement the PagerTabStripViewControllerDataSource childViewControllersForPagerTabStripViewController: method") + public func viewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { + assertionFailure("Sub-class must implement the PagerTabStripViewControllerDataSource viewControllersForPagerTabStripViewController: method") return [] } @@ -363,12 +363,12 @@ public class PagerTabStripViewController: UIViewController, UIScrollViewDelegate guard let dataSource = datasource else { fatalError("dataSource must not be nil") } - viewControllers = dataSource.childViewControllersForPagerTabStripViewController(self) + viewControllers = dataSource.viewControllersForPagerTabStripViewController(self) // viewControllers guard viewControllers.count != 0 else { - fatalError("childViewControllersForPagerTabStripViewController should provide at least one child view controller") + fatalError("viewControllersForPagerTabStripViewController should provide at least one child view controller") } - viewControllers.forEach { if !($0 is PagerTabStripChildItem) { fatalError("Every view controller provided by PagerTabStripViewControllerDataSource's childViewControllersForPagerTabStripViewController method must conform to PagerTabStripChildItem") }} + viewControllers.forEach { if !($0 is IndicatorInfoProvider) { fatalError("Every view controller provided by PagerTabStripViewControllerDataSource's viewControllersForPagerTabStripViewController method must conform to InfoProvider") }} } diff --git a/Sources/SegmentedPagerTabStripViewController.swift b/Sources/SegmentedPagerTabStripViewController.swift index 7906cde..5cb0d38 100644 --- a/Sources/SegmentedPagerTabStripViewController.swift +++ b/Sources/SegmentedPagerTabStripViewController.swift @@ -74,12 +74,12 @@ public class SegmentedPagerTabStripViewController: PagerTabStripViewController, func reloadSegmentedControl() throws { segmentedControl.removeAllSegments() for (index, item) in viewControllers.enumerate(){ - let child = item as! PagerTabStripChildItem - if let image = child.childInfoForPagerTabStripViewController(self).image { + let child = item as! IndicatorInfoProvider + if let image = child.infoForPagerTabStripViewController(self).image { segmentedControl.insertSegmentWithImage(image, atIndex: index, animated: false) } else { - segmentedControl.insertSegmentWithTitle(child.childInfoForPagerTabStripViewController(self).title, atIndex: index, animated: false) + segmentedControl.insertSegmentWithTitle(child.infoForPagerTabStripViewController(self).title, atIndex: index, animated: false) } } segmentedControl.selectedSegmentIndex = currentIndex diff --git a/Sources/TwitterPagerTabStripViewController.swift b/Sources/TwitterPagerTabStripViewController.swift index 75c0ed8..56c3084 100644 --- a/Sources/TwitterPagerTabStripViewController.swift +++ b/Sources/TwitterPagerTabStripViewController.swift @@ -164,11 +164,11 @@ public class TwitterPagerTabStripViewController: PagerTabStripViewController, Pa childTitleLabels.forEach { $0.removeFromSuperview() } childTitleLabels.removeAll() for (index, item) in viewControllers.enumerate() { - let child = item as! PagerTabStripChildItem - let childInfo = child.childInfoForPagerTabStripViewController(self) + let child = item as! IndicatorInfoProvider + let indicatorInfo = child.infoForPagerTabStripViewController(self) let navTitleLabel : UILabel = { let label = UILabel() - label.text = childInfo.title + label.text = indicatorInfo.title label.font = UIApplication.sharedApplication().statusBarOrientation.isPortrait ? settings.style.portraitTitleFont : settings.style.landscapeTitleFont label.textColor = settings.style.titleColor label.alpha = 0 diff --git a/XLPagerTabStrip.xcodeproj/project.pbxproj b/XLPagerTabStrip.xcodeproj/project.pbxproj index 6624fb9..c6a16a4 100644 --- a/XLPagerTabStrip.xcodeproj/project.pbxproj +++ b/XLPagerTabStrip.xcodeproj/project.pbxproj @@ -8,7 +8,7 @@ /* Begin PBXBuildFile section */ 281BFDC11C511C420090C26F /* ChildItemInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 281BFDC01C511C420090C26F /* ChildItemInfo.swift */; }; - 281BFDC31C511F120090C26F /* PagerTabStripOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 281BFDC21C511F120090C26F /* PagerTabStripOptions.swift */; }; + 281BFDC31C511F120090C26F /* PagerTabStripBehaviour.swift in Sources */ = {isa = PBXBuildFile; fileRef = 281BFDC21C511F120090C26F /* PagerTabStripBehaviour.swift */; }; 287D0A6E1C4B73BD004566D6 /* XLPagerTabStripTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 287D0A6D1C4B73BD004566D6 /* XLPagerTabStripTests.swift */; }; 28C83C841C54229A000B2902 /* BaseButtonBarPagerTabStripViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28C83C831C54229A000B2902 /* BaseButtonBarPagerTabStripViewController.swift */; }; 28E098BE1C5002D90083B788 /* PagerTabStripError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28E098BD1C5002D90083B788 /* PagerTabStripError.swift */; }; @@ -40,7 +40,7 @@ /* Begin PBXFileReference section */ 281BFDC01C511C420090C26F /* ChildItemInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChildItemInfo.swift; sourceTree = ""; }; - 281BFDC21C511F120090C26F /* PagerTabStripOptions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PagerTabStripOptions.swift; sourceTree = ""; }; + 281BFDC21C511F120090C26F /* PagerTabStripBehaviour.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PagerTabStripBehaviour.swift; sourceTree = ""; }; 287D0A6D1C4B73BD004566D6 /* XLPagerTabStripTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = XLPagerTabStripTests.swift; path = Tests/XLPagerTabStripTests.swift; sourceTree = SOURCE_ROOT; }; 28C83C831C54229A000B2902 /* BaseButtonBarPagerTabStripViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseButtonBarPagerTabStripViewController.swift; sourceTree = ""; }; 28E098BD1C5002D90083B788 /* PagerTabStripError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PagerTabStripError.swift; sourceTree = ""; }; @@ -58,7 +58,7 @@ CB71C6ED1C4EB988008EC806 /* SegmentedPagerTabStripViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SegmentedPagerTabStripViewController.swift; sourceTree = ""; }; CB7D614A1C529B9500A957BA /* FXPageControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FXPageControl.h; sourceTree = ""; }; CB7D614B1C529B9500A957BA /* FXPageControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FXPageControl.m; sourceTree = ""; }; - CB86ED6A1C4D6E6C00DA463B /* PagerTabStripViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PagerTabStripViewController.swift; sourceTree = ""; }; + CB86ED6A1C4D6E6C00DA463B /* PagerTabStripViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = PagerTabStripViewController.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; CBA0A1FA1C502DA300C5748C /* BarPagerTabStripViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BarPagerTabStripViewController.swift; sourceTree = ""; }; CBA0A1FB1C502DA300C5748C /* BarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BarView.swift; sourceTree = ""; }; CBBD43611C527E80001A748E /* TwitterPagerTabStripViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TwitterPagerTabStripViewController.swift; sourceTree = ""; }; @@ -155,7 +155,7 @@ 28E098BD1C5002D90083B788 /* PagerTabStripError.swift */, 28E098BF1C5003130083B788 /* SwipeDirection.swift */, 281BFDC01C511C420090C26F /* ChildItemInfo.swift */, - 281BFDC21C511F120090C26F /* PagerTabStripOptions.swift */, + 281BFDC21C511F120090C26F /* PagerTabStripBehaviour.swift */, ); path = Sources; sourceTree = ""; @@ -283,7 +283,7 @@ CBBD43621C527E80001A748E /* TwitterPagerTabStripViewController.swift in Sources */, CBA0A1FD1C502DA300C5748C /* BarView.swift in Sources */, CB7D614D1C529B9500A957BA /* FXPageControl.m in Sources */, - 281BFDC31C511F120090C26F /* PagerTabStripOptions.swift in Sources */, + 281BFDC31C511F120090C26F /* PagerTabStripBehaviour.swift in Sources */, CBA0A1FC1C502DA300C5748C /* BarPagerTabStripViewController.swift in Sources */, CB71C6EE1C4EB988008EC806 /* SegmentedPagerTabStripViewController.swift in Sources */, 28E098BE1C5002D90083B788 /* PagerTabStripError.swift in Sources */,