adds ButtonBarPagerTabStripController & examples
This commit is contained in:
parent
1a31d5a938
commit
71f664fe44
|
|
@ -12,6 +12,7 @@
|
|||
287D0A7E1C4B7B55004566D6 /* XLPagerTabStrip.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 287D0A7A1C4B7B26004566D6 /* XLPagerTabStrip.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
28F828D01C4B714D00330CF4 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28F828CF1C4B714D00330CF4 /* AppDelegate.swift */; };
|
||||
28F828DA1C4B714D00330CF4 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 28F828D81C4B714D00330CF4 /* LaunchScreen.storyboard */; };
|
||||
CB3697BF1C5177B4001FC5F8 /* ButtonBarExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB3697BE1C5177B4001FC5F8 /* ButtonBarExampleViewController.swift */; };
|
||||
CB71C6EB1C4EB964008EC806 /* SegmentedExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB71C6EA1C4EB964008EC806 /* SegmentedExampleViewController.swift */; };
|
||||
CB71C6F31C4FDDCE008EC806 /* PostCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB71C6F21C4FDDCE008EC806 /* PostCell.swift */; };
|
||||
CB86ED801C4D6F0D00DA463B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CB86ED6F1C4D6F0D00DA463B /* Assets.xcassets */; };
|
||||
|
|
@ -23,6 +24,7 @@
|
|||
CBA0A1FF1C50304500C5748C /* BarExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBA0A1FE1C50304500C5748C /* BarExampleViewController.swift */; };
|
||||
CBA0A2021C5032E100C5748C /* Storyboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CBA0A2011C5032E100C5748C /* Storyboard.storyboard */; };
|
||||
CBA0A2041C5033B400C5748C /* ReloadExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBA0A2031C5033B400C5748C /* ReloadExampleViewController.swift */; };
|
||||
CBBD435F1C5274AE001A748E /* NavButtonBarExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBBD435E1C5274AE001A748E /* NavButtonBarExampleViewController.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
|
|
@ -79,6 +81,7 @@
|
|||
28F828DB1C4B714D00330CF4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = Example/Info.plist; sourceTree = "<group>"; };
|
||||
28F828E01C4B714D00330CF4 /* ExampleUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ExampleUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
28F828E61C4B714D00330CF4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; name = Info.plist; path = Example/ExampleUITests/Info.plist; sourceTree = "<group>"; };
|
||||
CB3697BE1C5177B4001FC5F8 /* ButtonBarExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ButtonBarExampleViewController.swift; path = Example/Example/ButtonBarExampleViewController.swift; sourceTree = SOURCE_ROOT; };
|
||||
CB71C6EA1C4EB964008EC806 /* SegmentedExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SegmentedExampleViewController.swift; path = Example/SegmentedExampleViewController.swift; sourceTree = "<group>"; };
|
||||
CB71C6F21C4FDDCE008EC806 /* PostCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PostCell.swift; path = Example/PostCell.swift; sourceTree = "<group>"; };
|
||||
CB86ED6F1C4D6F0D00DA463B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = Example/Assets.xcassets; sourceTree = "<group>"; };
|
||||
|
|
@ -90,6 +93,7 @@
|
|||
CBA0A1FE1C50304500C5748C /* BarExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BarExampleViewController.swift; path = Example/BarExampleViewController.swift; sourceTree = "<group>"; };
|
||||
CBA0A2011C5032E100C5748C /* Storyboard.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Storyboard.storyboard; sourceTree = "<group>"; };
|
||||
CBA0A2031C5033B400C5748C /* ReloadExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ReloadExampleViewController.swift; path = Example/ReloadExampleViewController.swift; sourceTree = "<group>"; };
|
||||
CBBD435E1C5274AE001A748E /* NavButtonBarExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NavButtonBarExampleViewController.swift; path = Example/NavButtonBarExampleViewController.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
|
|
@ -170,8 +174,10 @@
|
|||
CB86ED891C4D712200DA463B /* ChildExampleViewController.swift */,
|
||||
CB86ED8D1C4D7A1800DA463B /* TableChildExampleViewController.swift */,
|
||||
CB71C6EA1C4EB964008EC806 /* SegmentedExampleViewController.swift */,
|
||||
CB3697BE1C5177B4001FC5F8 /* ButtonBarExampleViewController.swift */,
|
||||
CBA0A1FE1C50304500C5748C /* BarExampleViewController.swift */,
|
||||
CBA0A2031C5033B400C5748C /* ReloadExampleViewController.swift */,
|
||||
CBBD435E1C5274AE001A748E /* NavButtonBarExampleViewController.swift */,
|
||||
);
|
||||
name = Demo;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -317,7 +323,9 @@
|
|||
CB71C6EB1C4EB964008EC806 /* SegmentedExampleViewController.swift in Sources */,
|
||||
28F828D01C4B714D00330CF4 /* AppDelegate.swift in Sources */,
|
||||
CBA0A2041C5033B400C5748C /* ReloadExampleViewController.swift in Sources */,
|
||||
CB3697BF1C5177B4001FC5F8 /* ButtonBarExampleViewController.swift in Sources */,
|
||||
CBA0A1FF1C50304500C5748C /* BarExampleViewController.swift in Sources */,
|
||||
CBBD435F1C5274AE001A748E /* NavButtonBarExampleViewController.swift in Sources */,
|
||||
CB86ED8A1C4D712200DA463B /* ChildExampleViewController.swift in Sources */,
|
||||
CB86ED8E1C4D7A1800DA463B /* TableChildExampleViewController.swift in Sources */,
|
||||
CB71C6F31C4FDDCE008EC806 /* PostCell.swift in Sources */,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
//
|
||||
// ButtonBarExampleViewController.swift
|
||||
// Example
|
||||
//
|
||||
// Created by Santiago on 1/21/16.
|
||||
//
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import XLPagerTabStrip
|
||||
|
||||
public class ButtonBarExampleViewControlle: ButtonBarPagerTabStripViewController {
|
||||
var isReload = false
|
||||
|
||||
public override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
if pagerOptions.contains(.IsProgressiveIndicator) {
|
||||
pagerOptions = pagerOptions.remove(.IsProgressiveIndicator)!
|
||||
}
|
||||
|
||||
buttonBarView.selectedBar.backgroundColor = .orangeColor()
|
||||
buttonBarView.backgroundColor = UIColor(red: 7/255, green: 185/255, blue: 155/255, alpha: 1)
|
||||
}
|
||||
|
||||
// MARK: - PagerTabStripVIewControllerDataSource
|
||||
|
||||
public override func childViewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
let child_1 = TableChildExampleViewController(style: .Plain)
|
||||
let child_2 = ChildExampleViewController()
|
||||
let child_3 = TableChildExampleViewController(style: .Grouped)
|
||||
let child_4 = ChildExampleViewController()
|
||||
let child_5 = TableChildExampleViewController(style: .Plain)
|
||||
let child_6 = ChildExampleViewController()
|
||||
let child_7 = TableChildExampleViewController(style: .Grouped)
|
||||
let child_8 = ChildExampleViewController()
|
||||
|
||||
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] as Array
|
||||
let count = childViewControllers.count
|
||||
|
||||
for (index, _) in childViewControllers.enumerate(){
|
||||
let nElements = count - index
|
||||
let n = (Int(arc4random()) % nElements) + index
|
||||
if n != index{
|
||||
swap(&childViewControllers[index], &childViewControllers[n])
|
||||
}
|
||||
}
|
||||
let nItems = 1 + (rand() % 8)
|
||||
return Array(childViewControllers.prefix(Int(nItems)))
|
||||
}
|
||||
|
||||
public override func reloadPagerTabStripView() {
|
||||
isReload = true
|
||||
pagerOptions = rand() % 2 == 0 ? pagerOptions.union(.IsProgressiveIndicator) : (pagerOptions.remove(.IsProgressiveIndicator) ?? pagerOptions)
|
||||
pagerOptions = rand() % 2 == 0 ? pagerOptions.union(.IsElasticIndicatorLimit) : (pagerOptions.remove(.IsElasticIndicatorLimit) ?? pagerOptions)
|
||||
super.reloadPagerTabStripView()
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
//
|
||||
// NavButtonBarExampleViewController.swift
|
||||
// Example
|
||||
//
|
||||
// Created by Santiago on 1/22/16.
|
||||
//
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import XLPagerTabStrip
|
||||
|
||||
public class NavButtonBarExampleViewController: ButtonBarPagerTabStripViewController {
|
||||
var isReload = false
|
||||
|
||||
public override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
if pagerOptions.contains(.IsProgressiveIndicator) {
|
||||
pagerOptions = pagerOptions.remove(.IsProgressiveIndicator)!
|
||||
}
|
||||
|
||||
buttonBarView.backgroundColor = .clearColor()
|
||||
buttonBarView.selectedBar.backgroundColor = .orangeColor()
|
||||
buttonBarView.removeFromSuperview()
|
||||
navigationController?.navigationBar.addSubview(buttonBarView)
|
||||
|
||||
changeCurrentIndexProgressive = { (oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage: Float, changeCurrentIndex: Bool, animated: Bool) -> Void in
|
||||
guard changeCurrentIndex == true else { return }
|
||||
|
||||
oldCell?.label.textColor = UIColor(white: 1, alpha: 0.6)
|
||||
newCell?.label.textColor = .whiteColor()
|
||||
|
||||
if animated {
|
||||
UIView.animateWithDuration(0.1, animations: { () -> Void in
|
||||
newCell?.transform = CGAffineTransformMakeScale(1.0, 1.0)
|
||||
oldCell?.transform = CGAffineTransformMakeScale(0.8, 0.8)
|
||||
})
|
||||
}
|
||||
else {
|
||||
newCell?.transform = CGAffineTransformMakeScale(1.0, 1.0)
|
||||
oldCell?.transform = CGAffineTransformMakeScale(0.8, 0.8)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - PagerTabStripViewControllerDataSource
|
||||
|
||||
public override func childViewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
let child_1 = TableChildExampleViewController(style: .Plain)
|
||||
let child_2 = ChildExampleViewController()
|
||||
let child_3 = TableChildExampleViewController(style: .Grouped)
|
||||
let child_4 = ChildExampleViewController()
|
||||
let child_5 = TableChildExampleViewController(style: .Plain)
|
||||
let child_6 = ChildExampleViewController()
|
||||
let child_7 = TableChildExampleViewController(style: .Grouped)
|
||||
let child_8 = ChildExampleViewController()
|
||||
|
||||
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] as Array
|
||||
let count = childViewControllers.count
|
||||
|
||||
for (index, _) in childViewControllers.enumerate(){
|
||||
let nElements = count - index
|
||||
let n = (Int(arc4random()) % nElements) + index
|
||||
if n != index{
|
||||
swap(&childViewControllers[index], &childViewControllers[n])
|
||||
}
|
||||
}
|
||||
let nItems = 1 + (rand() % 8)
|
||||
return Array(childViewControllers.prefix(Int(nItems)))
|
||||
}
|
||||
|
||||
public override func reloadPagerTabStripView() {
|
||||
isReload = true
|
||||
pagerOptions = rand() % 2 == 0 ? pagerOptions.union(.IsProgressiveIndicator) : (pagerOptions.remove(.IsProgressiveIndicator) ?? pagerOptions)
|
||||
pagerOptions = rand() % 2 == 0 ? pagerOptions.union(.IsElasticIndicatorLimit) : (pagerOptions.remove(.IsElasticIndicatorLimit) ?? pagerOptions)
|
||||
super.reloadPagerTabStripView()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -10,7 +10,10 @@ import UIKit
|
|||
import XLPagerTabStrip
|
||||
|
||||
public class ReloadExampleViewController: UIViewController {
|
||||
@IBOutlet public var titleLabel: UILabel!
|
||||
@IBOutlet lazy public var titleLabel: UILabel! = {
|
||||
let label = UILabel()
|
||||
return label
|
||||
}()
|
||||
|
||||
public lazy var bigLabel: UILabel = {
|
||||
let bigLabel = UILabel()
|
||||
|
|
|
|||
|
|
@ -135,17 +135,17 @@
|
|||
<!--Buttons Example-->
|
||||
<scene sceneID="c3d-TB-Hyh">
|
||||
<objects>
|
||||
<viewController automaticallyAdjustsScrollViewInsets="NO" id="3jo-Zp-rsN" customClass="ReloadExampleViewController" sceneMemberID="viewController">
|
||||
<viewController automaticallyAdjustsScrollViewInsets="NO" id="3jo-Zp-rsN" customClass="ReloadExampleViewController" customModule="Example" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="sYC-OQ-Mga"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="LUh-C3-i05"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="TXd-Bq-amB">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="551"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="9rp-Lg-ckk">
|
||||
<rect key="frame" x="0.0" y="64" width="600" height="536"/>
|
||||
<rect key="frame" x="0.0" y="64" width="600" height="487"/>
|
||||
<connections>
|
||||
<segue destination="KF9-Il-rUn" kind="embed" id="PEH-Jc-gva"/>
|
||||
</connections>
|
||||
|
|
@ -230,6 +230,8 @@
|
|||
<connections>
|
||||
<segue destination="uba-Iz-2L2" kind="relationship" relationship="viewControllers" id="hNx-yW-oR3"/>
|
||||
<segue destination="g7J-zS-0bu" kind="relationship" relationship="viewControllers" id="WG0-Of-C4e"/>
|
||||
<segue destination="jWp-2W-r7X" kind="relationship" relationship="viewControllers" id="uoj-hE-05b"/>
|
||||
<segue destination="b3c-Kr-Yhe" kind="relationship" relationship="viewControllers" id="xMr-zV-ubn"/>
|
||||
</connections>
|
||||
</tabBarController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="YsA-SS-Qae" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
|
|
@ -284,19 +286,19 @@
|
|||
</objects>
|
||||
<point key="canvasLocation" x="1321" y="515"/>
|
||||
</scene>
|
||||
<!--Button Bar Example View Controller-->
|
||||
<!--Button Bar Example View Controlle-->
|
||||
<scene sceneID="Ctn-j0-KV6">
|
||||
<objects>
|
||||
<viewController automaticallyAdjustsScrollViewInsets="NO" id="KF9-Il-rUn" customClass="ButtonBarExampleViewController" sceneMemberID="viewController">
|
||||
<viewController automaticallyAdjustsScrollViewInsets="NO" id="KF9-Il-rUn" customClass="ButtonBarExampleViewControlle" customModule="Example" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="PhK-DQ-FzX"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="DoJ-0a-eFQ"/>
|
||||
</layoutGuides>
|
||||
<view key="view" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="nbo-eG-9Of">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="536"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="487"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="FH0-FX-IMd" customClass="XLButtonBarView">
|
||||
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="FH0-FX-IMd" customClass="ButtonBarView" customModule="XLPagerTabStrip">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
|
||||
<color key="backgroundColor" red="0.027450980390000001" green="0.72549019609999998" blue="0.60784313729999995" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<constraints>
|
||||
|
|
@ -309,15 +311,15 @@
|
|||
<inset key="sectionInset" minX="35" minY="0.0" maxX="35" maxY="0.0"/>
|
||||
</collectionViewFlowLayout>
|
||||
<cells>
|
||||
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="Cell" id="aWZ-BZ-wgL" customClass="XLButtonBarViewCell">
|
||||
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="Cell" id="aWZ-BZ-wgL" customClass="ButtonBarViewCell" customModule="XLPagerTabStrip">
|
||||
<rect key="frame" x="35" y="1" width="79" height="42"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
|
||||
<rect key="frame" x="0.0" y="0.0" width="79" height="42"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Idp-Ip-IhM">
|
||||
<rect key="frame" x="17" y="10" width="44" height="21"/>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Idp-Ip-IhM">
|
||||
<rect key="frame" x="17" y="10" width="45" height="21"/>
|
||||
<fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
|
||||
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
|
|
@ -336,7 +338,7 @@
|
|||
</cells>
|
||||
</collectionView>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="mcV-6K-P6b" customClass="UIScrollView">
|
||||
<rect key="frame" x="-5" y="43" width="610" height="493"/>
|
||||
<rect key="frame" x="-5" y="43" width="610" height="444"/>
|
||||
<color key="backgroundColor" red="0.93725490196078431" green="0.93725490196078431" blue="0.95686274509803926" alpha="1" colorSpace="calibratedRGB"/>
|
||||
</view>
|
||||
</subviews>
|
||||
|
|
@ -353,7 +355,7 @@
|
|||
</view>
|
||||
<toolbarItems/>
|
||||
<connections>
|
||||
<outlet property="buttonBarView" destination="FH0-FX-IMd" id="HvT-oB-FoW"/>
|
||||
<outlet property="buttonBarView" destination="FH0-FX-IMd" id="c7n-e6-pxW"/>
|
||||
<outlet property="containerView" destination="mcV-6K-P6b" id="feg-Vf-NRY"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
|
|
@ -455,17 +457,17 @@
|
|||
<!--Nav Button Bar Example View Controller-->
|
||||
<scene sceneID="fS9-Jp-SNl">
|
||||
<objects>
|
||||
<viewController id="y3e-AR-HhJ" customClass="NavButtonBarExampleViewController" sceneMemberID="viewController">
|
||||
<viewController id="y3e-AR-HhJ" customClass="NavButtonBarExampleViewController" customModule="Example" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="SCP-tk-3Q4"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="blo-XS-xG2"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="Z8p-ri-ydp">
|
||||
<rect key="frame" x="0.0" y="64" width="600" height="536"/>
|
||||
<rect key="frame" x="0.0" y="64" width="600" height="487"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<subviews>
|
||||
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="QoM-XF-R9X">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="536"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="487"/>
|
||||
<color key="backgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="calibratedRGB"/>
|
||||
</scrollView>
|
||||
</subviews>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,315 @@
|
|||
// ButtonBarPagerTabStripViewController.swift
|
||||
// XLPagerTabStrip ( https://github.com/xmartlabs/XLPagerTabStrip )
|
||||
//
|
||||
// Copyright (c) 2016 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
|
||||
|
||||
public class ButtonBarPagerTabStripViewController: PagerTabStripViewController, UICollectionViewDelegate, UICollectionViewDataSource {
|
||||
|
||||
public var changeCurrentIndex: ((oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, animated: Bool) -> Void)? = { _ in }
|
||||
public var changeCurrentIndexProgressive: ((oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage: Float, changeCurrentIndex: Bool, animated: Bool) -> Void)? = { _ in }
|
||||
|
||||
@IBOutlet public lazy var buttonBarView: ButtonBarView! = { [unowned self] in
|
||||
var flowLayout = UICollectionViewFlowLayout()
|
||||
flowLayout.scrollDirection = .Horizontal
|
||||
flowLayout.sectionInset = UIEdgeInsetsMake(0, 35, 0, 35)
|
||||
|
||||
let buttonBar: ButtonBarView = ButtonBarView(frame: CGRectMake(0, 0, self.view.frame.size.width, 44), collectionViewLayout: flowLayout)
|
||||
buttonBar.backgroundColor = .orangeColor()
|
||||
buttonBar.selectedBar.backgroundColor = .blackColor()
|
||||
buttonBar.autoresizingMask = .FlexibleWidth
|
||||
|
||||
var bundle = NSBundle(forClass: ButtonBarView.self)
|
||||
if let url = bundle.URLForResource("XLPagerTabStrip", withExtension: "bundle") {
|
||||
bundle = NSBundle(URL: url)!
|
||||
}
|
||||
|
||||
buttonBar.registerNib(UINib(nibName: "ButtonCell", bundle: bundle), forCellWithReuseIdentifier: "Cell")
|
||||
var newContainerViewFrame = self.containerView.frame
|
||||
newContainerViewFrame.origin.y = 44
|
||||
newContainerViewFrame.size.height = self.containerView.frame.size.height - (44 - self.containerView.frame.origin.y)
|
||||
self.containerView.frame = newContainerViewFrame
|
||||
return buttonBar
|
||||
}()
|
||||
|
||||
lazy private var cachedCellWidths: [CGFloat]? = { [unowned self] in
|
||||
return self.calculateWidths()
|
||||
}()
|
||||
|
||||
private var shouldUpdateButtonBarView = true
|
||||
private var isViewAppearing = false
|
||||
private var isViewRotating = false
|
||||
|
||||
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
|
||||
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
|
||||
}
|
||||
|
||||
required public init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
}
|
||||
|
||||
public override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
if buttonBarView.superview == nil {
|
||||
view.addSubview(buttonBarView)
|
||||
}
|
||||
if buttonBarView.delegate == nil {
|
||||
buttonBarView.delegate = self
|
||||
}
|
||||
if buttonBarView.dataSource == nil {
|
||||
buttonBarView.dataSource = self
|
||||
}
|
||||
|
||||
buttonBarView.labelFont = UIFont.boldSystemFontOfSize(18)
|
||||
buttonBarView.leftRightMargin = 8
|
||||
buttonBarView.scrollsToTop = false
|
||||
let flowLayout = buttonBarView.collectionViewLayout as! UICollectionViewFlowLayout
|
||||
flowLayout.scrollDirection = .Horizontal
|
||||
buttonBarView.showsHorizontalScrollIndicator = false
|
||||
}
|
||||
|
||||
public override func viewWillAppear(animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
buttonBarView.layoutIfNeeded()
|
||||
isViewAppearing = true
|
||||
}
|
||||
|
||||
public override func viewDidAppear(animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
isViewAppearing = true
|
||||
}
|
||||
|
||||
public override func viewDidLayoutSubviews() {
|
||||
super.viewDidLayoutSubviews()
|
||||
|
||||
guard isViewAppearing || isViewRotating else { return }
|
||||
|
||||
cachedCellWidths = calculateWidths()
|
||||
let flowLayout = buttonBarView.collectionViewLayout
|
||||
flowLayout.invalidateLayout()
|
||||
|
||||
buttonBarView.layoutIfNeeded()
|
||||
|
||||
// buttonBarView.moveToIndex(currentIndex, animated: false, swipeDirection: .None, pagerScroll: .ScrollOnlyIfOutOfScreen)
|
||||
}
|
||||
|
||||
// MARK: - View Rotation
|
||||
|
||||
public override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
|
||||
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
|
||||
|
||||
isViewRotating = true
|
||||
coordinator.animateAlongsideTransition(nil) { (context) -> Void in
|
||||
self.isViewRotating = false
|
||||
}
|
||||
}
|
||||
|
||||
public override func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
|
||||
super.willRotateToInterfaceOrientation(toInterfaceOrientation, duration: duration)
|
||||
isViewRotating = true
|
||||
}
|
||||
|
||||
// MARK: - Public Methods
|
||||
|
||||
public override func reloadPagerTabStripView() {
|
||||
super.reloadPagerTabStripView()
|
||||
|
||||
if isViewLoaded() {
|
||||
buttonBarView.reloadData()
|
||||
cachedCellWidths = calculateWidths()
|
||||
buttonBarView.moveToIndex(currentIndex, animated: false, swipeDirection: .None, pagerScroll: .YES)
|
||||
}
|
||||
}
|
||||
|
||||
public func calculateStretchedCellWidths(minimumCellWidths: Array<NSNumber>, suggestedStretchedCellWidth: CGFloat, previousNumberOfLargeCells: Int) -> CGFloat {
|
||||
var numberOfLargeCells = 0
|
||||
var totalWidthOfLargeCells: CGFloat = 0
|
||||
|
||||
for minimumCellWidthValue in minimumCellWidths {
|
||||
let minimumCellWidth = minimumCellWidthValue.floatValue
|
||||
if CGFloat(minimumCellWidth) > suggestedStretchedCellWidth {
|
||||
totalWidthOfLargeCells += CGFloat(minimumCellWidth)
|
||||
numberOfLargeCells++
|
||||
}
|
||||
}
|
||||
|
||||
guard numberOfLargeCells > previousNumberOfLargeCells else { return suggestedStretchedCellWidth }
|
||||
|
||||
let flowLayout = buttonBarView.collectionViewLayout as! UICollectionViewFlowLayout
|
||||
let collectionViewAvailiableWidth = buttonBarView.frame.size.width - flowLayout.sectionInset.left - flowLayout.sectionInset.right
|
||||
let numberOfCells = minimumCellWidths.count
|
||||
let cellSpacingTotal = CGFloat(numberOfCells - 1) * flowLayout.minimumInteritemSpacing
|
||||
|
||||
let numberOfSmallCells = numberOfCells - numberOfLargeCells
|
||||
let newSuggestedStretchedCellWidth = (collectionViewAvailiableWidth - totalWidthOfLargeCells - cellSpacingTotal) / CGFloat(numberOfSmallCells)
|
||||
|
||||
return calculateStretchedCellWidths(minimumCellWidths, suggestedStretchedCellWidth: newSuggestedStretchedCellWidth, previousNumberOfLargeCells: numberOfLargeCells)
|
||||
}
|
||||
|
||||
public override func pagerTabStripViewController(pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int) throws {
|
||||
guard shouldUpdateButtonBarView else { return }
|
||||
|
||||
let direction: SwipeDirection = (toIndex < fromIndex) ? .Right : .Left
|
||||
buttonBarView.moveToIndex(toIndex, animated: true, swipeDirection: direction, pagerScroll: .YES)
|
||||
if let changeCurrentIndex = changeCurrentIndex {
|
||||
let oldCell = buttonBarView.cellForItemAtIndexPath(NSIndexPath(forItem: currentIndex != fromIndex ? fromIndex : toIndex, inSection: 0)) as? ButtonBarViewCell
|
||||
let newCell = buttonBarView.cellForItemAtIndexPath(NSIndexPath(forItem: currentIndex, inSection: 0)) as? ButtonBarViewCell
|
||||
changeCurrentIndex(oldCell: oldCell, newCell: newCell, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
public override func pagerTabStripViewController(pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: Float, indexWasChanged: Bool) throws {
|
||||
guard shouldUpdateButtonBarView else { return }
|
||||
|
||||
buttonBarView.moveFromIndex(fromIndex, toIndex: toIndex, progressPercentage: progressPercentage, pagerScroll: .YES)
|
||||
if let changeCurrentIndexProgressive = changeCurrentIndexProgressive {
|
||||
let oldCell = buttonBarView.cellForItemAtIndexPath(NSIndexPath(forItem: currentIndex != fromIndex ? fromIndex : toIndex, inSection: 0)) as? ButtonBarViewCell
|
||||
let newCell = buttonBarView.cellForItemAtIndexPath(NSIndexPath(forItem: currentIndex, inSection: 0)) as? ButtonBarViewCell
|
||||
changeCurrentIndexProgressive(oldCell: oldCell, newCell: newCell, progressPercentage: progressPercentage, changeCurrentIndex: indexWasChanged, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UICollectionViewDelegateFlowLayut
|
||||
|
||||
public func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
|
||||
guard cachedCellWidths?.count > indexPath.row else { return CGSizeZero }
|
||||
|
||||
if let cellWidthValue = cachedCellWidths?[indexPath.row] {
|
||||
return CGSizeMake(cellWidthValue, collectionView.frame.size.height)
|
||||
}
|
||||
|
||||
return CGSizeZero
|
||||
}
|
||||
|
||||
public func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
|
||||
guard indexPath.item != currentIndex else { return }
|
||||
|
||||
buttonBarView.moveToIndex(indexPath.item, animated: true, swipeDirection: .None, pagerScroll: .YES)
|
||||
shouldUpdateButtonBarView = false
|
||||
|
||||
let oldCell = buttonBarView.cellForItemAtIndexPath(NSIndexPath(forItem: currentIndex, inSection: 0)) as! ButtonBarViewCell
|
||||
let newCell = buttonBarView.cellForItemAtIndexPath(NSIndexPath(forItem: indexPath.item, inSection: 0)) as! ButtonBarViewCell
|
||||
if pagerOptions.contains(.IsProgressiveIndicator) {
|
||||
if let changeCurrentIndexProgressive = changeCurrentIndexProgressive {
|
||||
changeCurrentIndexProgressive(oldCell: oldCell, newCell: newCell, progressPercentage: 1, changeCurrentIndex: true, animated: true)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if let changeCurrentIndex = changeCurrentIndex {
|
||||
changeCurrentIndex(oldCell: oldCell, newCell: newCell, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
moveToViewControllerAtIndex(indexPath.item)
|
||||
}
|
||||
|
||||
// MARK: - UICollectionViewDataSource
|
||||
|
||||
public func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
||||
return viewControllers.count
|
||||
}
|
||||
|
||||
public func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
|
||||
guard let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as? ButtonBarViewCell else {
|
||||
fatalError("UICollectionViewCell should be or extend XLButtonBarViewCell")
|
||||
}
|
||||
|
||||
let childController = viewControllers[indexPath.item] as? PagerTabStripChildItem
|
||||
|
||||
cell.label.text = childController?.childHeaderForPagerTabStripViewController(self).title
|
||||
if let image = childController?.childHeaderForPagerTabStripViewController(self).image {
|
||||
cell.imageView.image = image
|
||||
}
|
||||
|
||||
if let highlightedImage = childController?.childHeaderForPagerTabStripViewController(self).highlightedImage {
|
||||
cell.imageView.highlightedImage = highlightedImage
|
||||
}
|
||||
|
||||
if pagerOptions.contains(.IsProgressiveIndicator) {
|
||||
if let changeCurrentIndexProgressive = changeCurrentIndexProgressive {
|
||||
changeCurrentIndexProgressive(oldCell: currentIndex == indexPath.item ? nil : cell, newCell: currentIndex == indexPath.item ? cell : nil, progressPercentage: 1, changeCurrentIndex: true, animated: false)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if let changeCurrentIndex = changeCurrentIndex {
|
||||
changeCurrentIndex(oldCell: currentIndex == indexPath.item ? nil : cell, newCell: currentIndex == indexPath.item ? cell : nil, animated: false)
|
||||
}
|
||||
}
|
||||
|
||||
return cell
|
||||
}
|
||||
|
||||
// MARK: - UIScrollViewDelegate
|
||||
|
||||
public override func scrollViewDidEndScrollingAnimation(scrollView: UIScrollView) {
|
||||
super.scrollViewDidEndScrollingAnimation(scrollView)
|
||||
|
||||
guard scrollView == containerView else { return }
|
||||
shouldUpdateButtonBarView = true
|
||||
}
|
||||
|
||||
private func calculateWidths() -> [CGFloat] {
|
||||
let flowLayout = self.buttonBarView.collectionViewLayout as! UICollectionViewFlowLayout
|
||||
let numberOfCells = self.viewControllers.count
|
||||
|
||||
var minimumCellWidths = [CGFloat]()
|
||||
var collectionViewContentWidth: CGFloat = 0
|
||||
|
||||
for viewController in self.viewControllers {
|
||||
let childController = viewController as? PagerTabStripChildItem
|
||||
|
||||
let label = UILabel()
|
||||
label.translatesAutoresizingMaskIntoConstraints = false
|
||||
label.font = self.buttonBarView.labelFont!
|
||||
label.text = childController?.childHeaderForPagerTabStripViewController(self).title
|
||||
let labelSize = label.intrinsicContentSize()
|
||||
|
||||
let minimumCellWidth = labelSize.width + CGFloat(self.buttonBarView.leftRightMargin! * 2)
|
||||
minimumCellWidths.append(minimumCellWidth)
|
||||
|
||||
collectionViewContentWidth += minimumCellWidth
|
||||
}
|
||||
|
||||
let cellSpacingTotal = CGFloat(numberOfCells - 1) * flowLayout.minimumInteritemSpacing
|
||||
collectionViewContentWidth += cellSpacingTotal
|
||||
|
||||
let collectionViewAvailableVisibleWidth = self.buttonBarView.frame.size.width - flowLayout.sectionInset.left - flowLayout.sectionInset.right
|
||||
|
||||
if self.buttonBarView.shouldCellsFillAvailiableWidth || collectionViewAvailableVisibleWidth < collectionViewContentWidth {
|
||||
return minimumCellWidths
|
||||
}
|
||||
else {
|
||||
let stretchedCellWidthIfAllEqual = (collectionViewAvailableVisibleWidth - cellSpacingTotal) / CGFloat(numberOfCells)
|
||||
let generalMinimumCellWidth = self.calculateStretchedCellWidths(minimumCellWidths, suggestedStretchedCellWidth: stretchedCellWidthIfAllEqual, previousNumberOfLargeCells: 0)
|
||||
var stretchedCellWidths = [CGFloat]()
|
||||
|
||||
for minimumCellWidthValue in minimumCellWidths {
|
||||
let cellWidth = (minimumCellWidthValue > generalMinimumCellWidth) ? minimumCellWidthValue : generalMinimumCellWidth
|
||||
stretchedCellWidths.append(cellWidth)
|
||||
}
|
||||
|
||||
return stretchedCellWidths
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,170 @@
|
|||
// ButtonBarView.swift
|
||||
// XLPagerTabStrip ( https://github.com/xmartlabs/XLPagerTabStrip )
|
||||
//
|
||||
// Copyright (c) 2016 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 UIKit
|
||||
|
||||
public enum PagerScroll: Int {
|
||||
case NO = 1, YES = 2, ScrollOnlyIfOutOfScreen = 3
|
||||
}
|
||||
|
||||
public enum SelectedBarAlignment: Int {
|
||||
case Left = 1, Center = 2, Right = 3, Progressive = 4
|
||||
}
|
||||
|
||||
public class ButtonBarView: UICollectionView {
|
||||
|
||||
public lazy var selectedBar: UIView = { [unowned self] in
|
||||
let bar = UIView(frame: CGRectMake(0, self.frame.size.height - CGFloat(self.selectedBarHeight), 0, CGFloat(self.selectedBarHeight)))
|
||||
bar.layer.zPosition = 9999
|
||||
bar.backgroundColor = .blackColor()
|
||||
return bar
|
||||
}()
|
||||
|
||||
public var shouldCellsFillAvailiableWidth = true
|
||||
var selectedBarHeight = 5
|
||||
var selectedBarAlignment: SelectedBarAlignment = .Center
|
||||
var labelFont: UIFont? = nil
|
||||
var leftRightMargin: Int? = nil
|
||||
var selectedIndex = 0
|
||||
|
||||
required public init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
addSubview(selectedBar)
|
||||
}
|
||||
|
||||
override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
|
||||
super.init(frame: frame, collectionViewLayout: layout)
|
||||
addSubview(selectedBar)
|
||||
}
|
||||
|
||||
public func moveToIndex(toIndex: Int, animated: Bool, swipeDirection: SwipeDirection, pagerScroll: PagerScroll) -> Void {
|
||||
selectedIndex = toIndex
|
||||
updateSelectedBarPosition(animated, swipeDirection: swipeDirection, pagerScroll: pagerScroll)
|
||||
}
|
||||
|
||||
public func moveFromIndex(fromIndex: Int, toIndex: Int, progressPercentage: Float,pagerScroll: PagerScroll) -> Void {
|
||||
selectedIndex = (progressPercentage > 0.5) ? toIndex : fromIndex
|
||||
|
||||
let fromFrame = layoutAttributesForItemAtIndexPath(NSIndexPath(forItem: fromIndex, inSection: 0))!.frame
|
||||
let numberOfItems = dataSource!.collectionView(self, numberOfItemsInSection: 0)
|
||||
var toFrame: CGRect
|
||||
|
||||
if toIndex < 0 || toIndex > numberOfItems - 1 {
|
||||
if toIndex < 0 {
|
||||
let cellAtts = layoutAttributesForItemAtIndexPath(NSIndexPath(forItem: 0, inSection: 0))
|
||||
toFrame = CGRectOffset(cellAtts!.frame, -cellAtts!.frame.size.width, 0)
|
||||
}
|
||||
else {
|
||||
let cellAtts = layoutAttributesForItemAtIndexPath(NSIndexPath(forItem: (numberOfItems - 1), inSection: 0))
|
||||
toFrame = CGRectOffset(cellAtts!.frame, cellAtts!.frame.size.width, 0)
|
||||
}
|
||||
}
|
||||
else {
|
||||
toFrame = layoutAttributesForItemAtIndexPath(NSIndexPath(forItem: toIndex, inSection: 0))!.frame
|
||||
}
|
||||
|
||||
var targetFrame = fromFrame
|
||||
targetFrame.size.height = selectedBar.frame.size.height
|
||||
targetFrame.size.width += (toFrame.size.width - fromFrame.size.width) * CGFloat(progressPercentage)
|
||||
targetFrame.origin.x += (toFrame.origin.x - fromFrame.origin.x) * CGFloat(progressPercentage)
|
||||
|
||||
selectedBar.frame = CGRectMake(targetFrame.origin.x, selectedBar.frame.origin.y, targetFrame.size.width, selectedBar.frame.size.height)
|
||||
|
||||
var targetContentOffset: CGFloat = 0.0
|
||||
if contentSize.width > frame.size.width {
|
||||
let toContentOffset = contentOffsetForCell(withFrame: toFrame, andIndex: toIndex)
|
||||
let fromContentOffset = contentOffsetForCell(withFrame: fromFrame, andIndex: fromIndex)
|
||||
|
||||
targetContentOffset = fromContentOffset + ((toContentOffset - fromContentOffset) * CGFloat(progressPercentage))
|
||||
}
|
||||
|
||||
let animated = abs(contentOffset.x - targetContentOffset) > 30 || (fromIndex == toIndex)
|
||||
setContentOffset(CGPointMake(targetContentOffset, 0), animated: animated)
|
||||
}
|
||||
|
||||
public func updateSelectedBarPosition(animated: Bool, swipeDirection: SwipeDirection, pagerScroll: PagerScroll) -> Void {
|
||||
var selectedBarFrame = selectedBar.frame
|
||||
|
||||
let selectedCellIndexPath = NSIndexPath(forItem: selectedIndex, inSection: 0)
|
||||
let attributes = layoutAttributesForItemAtIndexPath(selectedCellIndexPath)
|
||||
let selectedCellFrame = attributes!.frame
|
||||
|
||||
updateContentOffset(animated, pagerScroll: pagerScroll, toFrame: selectedCellFrame, toIndex: selectedCellIndexPath.row)
|
||||
|
||||
selectedBarFrame.size.width = selectedCellFrame.size.width
|
||||
selectedBarFrame.origin.x = selectedCellFrame.origin.x
|
||||
|
||||
if animated {
|
||||
UIView.animateWithDuration(0.3, animations: { [weak self] in
|
||||
self?.selectedBar.frame = selectedBarFrame
|
||||
})
|
||||
}
|
||||
else {
|
||||
selectedBar.frame = selectedBarFrame
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private func updateContentOffset(animated: Bool, pagerScroll: PagerScroll, toFrame: CGRect, toIndex: Int) -> Void {
|
||||
guard pagerScroll != .NO else {
|
||||
return
|
||||
}
|
||||
|
||||
if pagerScroll == .ScrollOnlyIfOutOfScreen {
|
||||
if (toFrame.origin.x >= contentOffset.x) && (toFrame.origin.x < (contentOffset.x + frame.size.width - contentInset.left)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
let targetContentOffset = contentSize.width > frame.size.width ? contentOffsetForCell(withFrame: toFrame, andIndex: toIndex) : 0
|
||||
setContentOffset(CGPointMake(targetContentOffset, 0), animated: animated)
|
||||
}
|
||||
|
||||
private func contentOffsetForCell(withFrame cellFrame: CGRect, andIndex index: Int) -> CGFloat {
|
||||
let sectionInset = (collectionViewLayout as? UICollectionViewFlowLayout)!.sectionInset
|
||||
var alignmentOffset: CGFloat = 0.0
|
||||
|
||||
switch selectedBarAlignment {
|
||||
case .Left:
|
||||
alignmentOffset = sectionInset.left
|
||||
case .Right:
|
||||
alignmentOffset = frame.size.width - sectionInset.right - cellFrame.size.width
|
||||
case .Center:
|
||||
alignmentOffset = (frame.size.width - cellFrame.size.width) * 0.5
|
||||
case .Progressive:
|
||||
let cellHalfWidth = cellFrame.size.width * 0.5
|
||||
let leftAlignmentOffset = sectionInset.left + cellHalfWidth
|
||||
let rightAlignmentOffset = frame.size.width - sectionInset.right - cellHalfWidth
|
||||
let numberOfItems = dataSource!.collectionView(self, numberOfItemsInSection: 0)
|
||||
let progress = index / (numberOfItems - 1)
|
||||
alignmentOffset = leftAlignmentOffset + (rightAlignmentOffset - leftAlignmentOffset) * CGFloat(progress) - cellHalfWidth
|
||||
}
|
||||
|
||||
var contentOffset = cellFrame.origin.x - alignmentOffset
|
||||
contentOffset = max(0, contentOffset)
|
||||
contentOffset = min(contentSize.width - frame.size.width, contentOffset)
|
||||
return contentOffset
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
// ButtonBarViewCell.swift
|
||||
// XLPagerTabStrip ( https://github.com/xmartlabs/XLPagerTabStrip )
|
||||
//
|
||||
// Copyright (c) 2016 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
|
||||
|
||||
public class ButtonBarViewCell: UICollectionViewCell {
|
||||
|
||||
@IBOutlet public var imageView: UIImageView!
|
||||
@IBOutlet public lazy var label: UILabel! = { [unowned self] in
|
||||
let label = UILabel(frame: self.contentView.bounds)
|
||||
label.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
|
||||
label.textAlignment = .Center
|
||||
label.font = UIFont.systemFontOfSize(14.0, weight: UIFontWeightMedium)
|
||||
return label
|
||||
}()
|
||||
|
||||
public override func willMoveToSuperview(newSuperview: UIView?) {
|
||||
super.willMoveToSuperview(newSuperview)
|
||||
|
||||
if label.superview != nil {
|
||||
contentView.addSubview(label)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9531" systemVersion="15A284" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="ButtonBarViewCell" customModule="XLPagerTabStrip" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="80" height="40"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4bA-d3-zGi">
|
||||
<rect key="frame" x="18" y="10" width="45" height="21"/>
|
||||
<fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="centerX" secondItem="4bA-d3-zGi" secondAttribute="centerX" id="kcH-EZ-rRx"/>
|
||||
<constraint firstAttribute="centerY" secondItem="4bA-d3-zGi" secondAttribute="centerY" id="lcE-iT-kgq"/>
|
||||
</constraints>
|
||||
<nil key="simulatedStatusBarMetrics"/>
|
||||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
||||
<connections>
|
||||
<outlet property="label" destination="4bA-d3-zGi" id="Ckx-bG-ZhP"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="304" y="552"/>
|
||||
</view>
|
||||
</objects>
|
||||
</document>
|
||||
|
|
@ -28,7 +28,7 @@ public struct ChildItemInfo {
|
|||
|
||||
public var title: String
|
||||
public var image: UIImage?
|
||||
// public var highlightedImage: UIImage?
|
||||
public var highlightedImage: UIImage?
|
||||
public var color: UIColor?
|
||||
|
||||
public init(title: String) {
|
||||
|
|
@ -42,7 +42,7 @@ public struct ChildItemInfo {
|
|||
|
||||
public init(title: String, image: UIImage?, highlightedImage: UIImage?) {
|
||||
self.init(title: title, image: image)
|
||||
// self.highlightedImage = highlightedImage
|
||||
self.highlightedImage = highlightedImage
|
||||
}
|
||||
|
||||
public init(title: String, image: UIImage?, highlightedImage: UIImage?, color: UIColor?){
|
||||
|
|
|
|||
|
|
@ -14,6 +14,10 @@
|
|||
28E098C01C5003130083B788 /* SwipeDirection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28E098BF1C5003130083B788 /* SwipeDirection.swift */; };
|
||||
28F828811C494B2C00330CF4 /* XLPagerTabStrip.h in Headers */ = {isa = PBXBuildFile; fileRef = 28F828801C494B2C00330CF4 /* XLPagerTabStrip.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
28F828881C494B2C00330CF4 /* XLPagerTabStrip.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 28F8287D1C494B2C00330CF4 /* XLPagerTabStrip.framework */; };
|
||||
CB0986C41C51391600DF7087 /* ButtonBarPagerTabStripViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB0986C31C51391600DF7087 /* ButtonBarPagerTabStripViewController.swift */; };
|
||||
CB0986C61C51395E00DF7087 /* ButtonBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB0986C51C51395E00DF7087 /* ButtonBarView.swift */; };
|
||||
CB0986C81C5158A000DF7087 /* ButtonBarViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB0986C71C5158A000DF7087 /* ButtonBarViewCell.swift */; };
|
||||
CB0986CA1C515D9A00DF7087 /* ButtonCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = CB0986C91C515D9A00DF7087 /* ButtonCell.xib */; };
|
||||
CB71C6EE1C4EB988008EC806 /* SegmentedPagerTabStripViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB71C6ED1C4EB988008EC806 /* SegmentedPagerTabStripViewController.swift */; };
|
||||
CB86ED6B1C4D6E6C00DA463B /* PagerTabStripViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB86ED6A1C4D6E6C00DA463B /* PagerTabStripViewController.swift */; };
|
||||
CBA0A1FC1C502DA300C5748C /* BarPagerTabStripViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBA0A1FA1C502DA300C5748C /* BarPagerTabStripViewController.swift */; };
|
||||
|
|
@ -42,6 +46,10 @@
|
|||
28F828871C494B2C00330CF4 /* XLPagerTabStripTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = XLPagerTabStripTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
28F8288E1C494B2C00330CF4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; name = Info.plist; path = Tests/Info.plist; sourceTree = "<group>"; };
|
||||
28F8289B1C494BF100330CF4 /* Playground.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = Playground.playground; sourceTree = "<group>"; };
|
||||
CB0986C31C51391600DF7087 /* ButtonBarPagerTabStripViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonBarPagerTabStripViewController.swift; sourceTree = "<group>"; };
|
||||
CB0986C51C51395E00DF7087 /* ButtonBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonBarView.swift; sourceTree = "<group>"; };
|
||||
CB0986C71C5158A000DF7087 /* ButtonBarViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonBarViewCell.swift; sourceTree = "<group>"; };
|
||||
CB0986C91C515D9A00DF7087 /* ButtonCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ButtonCell.xib; sourceTree = "<group>"; };
|
||||
CB71C6ED1C4EB988008EC806 /* SegmentedPagerTabStripViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SegmentedPagerTabStripViewController.swift; sourceTree = "<group>"; };
|
||||
CB86ED6A1C4D6E6C00DA463B /* PagerTabStripViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PagerTabStripViewController.swift; sourceTree = "<group>"; };
|
||||
CBA0A1FA1C502DA300C5748C /* BarPagerTabStripViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BarPagerTabStripViewController.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -70,7 +78,10 @@
|
|||
281BFDBE1C511B890090C26F /* Views */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
CB0986C91C515D9A00DF7087 /* ButtonCell.xib */,
|
||||
CBA0A1FB1C502DA300C5748C /* BarView.swift */,
|
||||
CB0986C51C51395E00DF7087 /* ButtonBarView.swift */,
|
||||
CB0986C71C5158A000DF7087 /* ButtonBarViewCell.swift */,
|
||||
);
|
||||
name = Views;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -81,6 +92,7 @@
|
|||
CBA0A1FA1C502DA300C5748C /* BarPagerTabStripViewController.swift */,
|
||||
CB86ED6A1C4D6E6C00DA463B /* PagerTabStripViewController.swift */,
|
||||
CB71C6ED1C4EB988008EC806 /* SegmentedPagerTabStripViewController.swift */,
|
||||
CB0986C31C51391600DF7087 /* ButtonBarPagerTabStripViewController.swift */,
|
||||
);
|
||||
name = Controllers;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -227,6 +239,7 @@
|
|||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
CB0986CA1C515D9A00DF7087 /* ButtonCell.xib in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
@ -244,6 +257,7 @@
|
|||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
CB0986C61C51395E00DF7087 /* ButtonBarView.swift in Sources */,
|
||||
CBA0A1FD1C502DA300C5748C /* BarView.swift in Sources */,
|
||||
281BFDC31C511F120090C26F /* PagerTabStripOptions.swift in Sources */,
|
||||
CBA0A1FC1C502DA300C5748C /* BarPagerTabStripViewController.swift in Sources */,
|
||||
|
|
@ -252,6 +266,8 @@
|
|||
281BFDC11C511C420090C26F /* ChildItemInfo.swift in Sources */,
|
||||
CB86ED6B1C4D6E6C00DA463B /* PagerTabStripViewController.swift in Sources */,
|
||||
28E098C01C5003130083B788 /* SwipeDirection.swift in Sources */,
|
||||
CB0986C81C5158A000DF7087 /* ButtonBarViewCell.swift in Sources */,
|
||||
CB0986C41C51391600DF7087 /* ButtonBarPagerTabStripViewController.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue