update some class names
This commit is contained in:
parent
a088f9fcdd
commit
0811a95ada
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class YoutubeExampleViewController: BaseButtonBarPagerTabStripViewController<You
|
|||
required init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
|
||||
buttonBarItemSpec = ButtonBarItemSpec.NibFile(nibName: "YoutubeIconCell", bundle: NSBundle(forClass: YoutubeIconCell.self), width: { (cell: ChildItemInfo) -> 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<You
|
|||
|
||||
// MARK: - PagerTabStripVIewControllerDataSource
|
||||
|
||||
override func childViewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [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
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 991 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 83 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 133 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 110 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 147 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 82 KiB |
52
README.md
52
README.md
|
|
@ -24,18 +24,44 @@ Android [PagerTabStrip](http://developer.android.com/reference/android/support/v
|
|||
</tr>
|
||||
</table>
|
||||
|
||||
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.
|
||||
|
||||
<img src="Example/barButton.gif" width="250"/>
|
||||
|
||||
### Bar
|
||||
|
||||
This mode doesn't show a title neither a image. It only shows a bar that indicates the current view controller.
|
||||
|
||||
<img src="Example/bar.gif" width="250"/>
|
||||
|
||||
### Twitter
|
||||
|
||||
Long time ago twitter app made use of this type of pager in the app main screen.
|
||||
|
||||
<img src="Example/twitter.gif" width="250"/>
|
||||
|
||||
### Segmented
|
||||
|
||||
This mode uses a `UIsegmentedControl` to indicates which is the view controller being displayed.
|
||||
|
||||
<img src="Example/segmented.gif" width="250"/>
|
||||
|
||||
## 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
|
||||
|
|
|
|||
|
|
@ -230,10 +230,10 @@ public class BaseButtonBarPagerTabStripViewController<ButtonBarCellType : UIColl
|
|||
guard let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as? ButtonBarCellType 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)
|
||||
|
||||
configureCell(cell, childInfo: childInfo)
|
||||
configureCell(cell, indicatorInfo: indicatorInfo)
|
||||
|
||||
if pagerBehaviour.isProgressiveIndicator {
|
||||
if let changeCurrentIndexProgressive = changeCurrentIndexProgressive {
|
||||
|
|
@ -258,7 +258,7 @@ public class BaseButtonBarPagerTabStripViewController<ButtonBarCellType : UIColl
|
|||
shouldUpdateButtonBarView = true
|
||||
}
|
||||
|
||||
public func configureCell(cell: ButtonBarCellType, childInfo: ChildItemInfo){
|
||||
public func configureCell(cell: ButtonBarCellType, indicatorInfo: IndicatorInfo){
|
||||
fatalError("You must override this method to set up ButtonBarView cell accordingly")
|
||||
}
|
||||
|
||||
|
|
@ -270,15 +270,15 @@ public class BaseButtonBarPagerTabStripViewController<ButtonBarCellType : UIColl
|
|||
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
|
||||
}
|
||||
|
|
@ -333,12 +333,12 @@ public class ExampleBaseButtonBarPagerTabStripViewController: BaseButtonBarPager
|
|||
})
|
||||
}
|
||||
|
||||
public override func configureCell(cell: ButtonBarViewCell, childInfo: ChildItemInfo){
|
||||
cell.label.text = childInfo.title
|
||||
if let image = childInfo.image {
|
||||
public override func configureCell(cell: ButtonBarViewCell, indicatorInfo: IndicatorInfo){
|
||||
cell.label.text = indicatorInfo.title
|
||||
if let image = indicatorInfo.image {
|
||||
cell.imageView.image = image
|
||||
}
|
||||
if let highlightedImage = childInfo.highlightedImage {
|
||||
if let highlightedImage = indicatorInfo.highlightedImage {
|
||||
cell.imageView.highlightedImage = highlightedImage
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,10 +26,10 @@ import Foundation
|
|||
|
||||
public enum ButtonBarItemSpec<CellType: UICollectionViewCell> {
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ import Foundation
|
|||
|
||||
public enum PagerTabStripError: ErrorType {
|
||||
case DataSourceMustNotBeNil
|
||||
case ChildViewControllerMustConformToPagerTabStripChildItem
|
||||
case ChildViewControllerMustConformToInfoProvider
|
||||
case CurrentIndexIsGreaterThanChildsCount
|
||||
case PagerTabStripChildViewControllersMustContainAtLeastOneViewController
|
||||
case ViewControllerNotContainedInPagerTabStripChildViewControllers
|
||||
|
|
|
|||
|
|
@ -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") }}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 = "<group>"; };
|
||||
281BFDC21C511F120090C26F /* PagerTabStripOptions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PagerTabStripOptions.swift; sourceTree = "<group>"; };
|
||||
281BFDC21C511F120090C26F /* PagerTabStripBehaviour.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PagerTabStripBehaviour.swift; sourceTree = "<group>"; };
|
||||
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 = "<group>"; };
|
||||
28E098BD1C5002D90083B788 /* PagerTabStripError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PagerTabStripError.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -58,7 +58,7 @@
|
|||
CB71C6ED1C4EB988008EC806 /* SegmentedPagerTabStripViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SegmentedPagerTabStripViewController.swift; sourceTree = "<group>"; };
|
||||
CB7D614A1C529B9500A957BA /* FXPageControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FXPageControl.h; sourceTree = "<group>"; };
|
||||
CB7D614B1C529B9500A957BA /* FXPageControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FXPageControl.m; sourceTree = "<group>"; };
|
||||
CB86ED6A1C4D6E6C00DA463B /* PagerTabStripViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PagerTabStripViewController.swift; sourceTree = "<group>"; };
|
||||
CB86ED6A1C4D6E6C00DA463B /* PagerTabStripViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = PagerTabStripViewController.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
|
||||
CBA0A1FA1C502DA300C5748C /* BarPagerTabStripViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BarPagerTabStripViewController.swift; sourceTree = "<group>"; };
|
||||
CBA0A1FB1C502DA300C5748C /* BarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BarView.swift; sourceTree = "<group>"; };
|
||||
CBBD43611C527E80001A748E /* TwitterPagerTabStripViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TwitterPagerTabStripViewController.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -155,7 +155,7 @@
|
|||
28E098BD1C5002D90083B788 /* PagerTabStripError.swift */,
|
||||
28E098BF1C5003130083B788 /* SwipeDirection.swift */,
|
||||
281BFDC01C511C420090C26F /* ChildItemInfo.swift */,
|
||||
281BFDC21C511F120090C26F /* PagerTabStripOptions.swift */,
|
||||
281BFDC21C511F120090C26F /* PagerTabStripBehaviour.swift */,
|
||||
);
|
||||
path = Sources;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -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 */,
|
||||
|
|
|
|||
Loading…
Reference in New Issue