Instantly share code, notes, and snippets.
Created
March 7, 2017 18:47
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save wwe-johndpope/abd6446d563a05ff9ea66a3671ed72b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NavButtonBarExampleViewController.swift | |
// XLPagerTabStrip ( https://github.com/xmartlabs/XLPagerTabStrip ) | |
// | |
// Copyright (c) 2017 Xmartlabs ( http://xmartlabs.com ) | |
// | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal | |
// in the Software without restriction, including without limitation the rights | |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
// copies of the Software, and to permit persons to whom the Software is | |
// furnished to do so, subject to the following conditions: | |
// | |
// The above copyright notice and this permission notice shall be included in | |
// all copies or substantial portions of the Software. | |
// | |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
// THE SOFTWARE. | |
import Foundation | |
import XLPagerTabStrip | |
class NavButtonBarExampleViewController: ButtonBarPagerTabStripViewController { | |
var isReload = false | |
override func viewDidLoad() { | |
// set up style before super view did load is executed | |
settings.style.buttonBarBackgroundColor = .clear | |
settings.style.selectedBarBackgroundColor = .orange | |
//- | |
super.viewDidLoad() | |
buttonBarView.removeFromSuperview() | |
navigationController?.navigationBar.addSubview(buttonBarView) | |
changeCurrentIndexProgressive = { (oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in | |
guard changeCurrentIndex == true else { return } | |
oldCell?.label.textColor = UIColor(white: 1, alpha: 0.6) | |
newCell?.label.textColor = .white | |
if animated { | |
UIView.animate(withDuration: 0.1, animations: { () -> Void in | |
newCell?.transform = CGAffineTransform(scaleX: 1.0, y: 1.0) | |
oldCell?.transform = CGAffineTransform(scaleX: 0.8, y: 0.8) | |
}) | |
} | |
else { | |
newCell?.transform = CGAffineTransform(scaleX: 1.0, y: 1.0) | |
oldCell?.transform = CGAffineTransform(scaleX: 0.8, y: 0.8) | |
} | |
} | |
} | |
// MARK: - PagerTabStripDataSource | |
override func viewControllers(for 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") | |
let child_4 = ChildExampleViewController(itemInfo: "View 1") | |
let child_5 = TableChildExampleViewController(style: .plain, itemInfo: "Table View 3") | |
let child_6 = ChildExampleViewController(itemInfo: "View 2") | |
let child_7 = TableChildExampleViewController(style: .grouped, itemInfo: "Table View 4") | |
let child_8 = ChildExampleViewController(itemInfo: "View 3") | |
guard isReload else { | |
return [child_1, child_2, child_3, child_4, child_5, child_6, child_7, child_8] | |
} | |
var childViewControllers = [child_1, child_2, child_3, child_4, child_6, child_7, child_8] | |
for (index, _) in childViewControllers.enumerated(){ | |
let nElements = childViewControllers.count - index | |
let n = (Int(arc4random()) % nElements) + index | |
if n != index{ | |
swap(&childViewControllers[index], &childViewControllers[n]) | |
} | |
} | |
let nItems = 1 + (arc4random() % 8) | |
return Array(childViewControllers.prefix(Int(nItems))) | |
} | |
override func reloadPagerTabStripView() { | |
isReload = true | |
if arc4random() % 2 == 0 { | |
pagerBehaviour = .progressive(skipIntermediateViewControllers: arc4random() % 2 == 0, elasticIndicatorLimit: arc4random() % 2 == 0 ) | |
} | |
else { | |
pagerBehaviour = .common(skipIntermediateViewControllers: arc4random() % 2 == 0) | |
} | |
super.reloadPagerTabStripView() | |
} | |
override func configureCell(_ cell: ButtonBarViewCell, indicatorInfo: IndicatorInfo) { | |
super.configureCell(cell, indicatorInfo: indicatorInfo) | |
cell.backgroundColor = .clear | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment