Skip to content

Commit

Permalink
clean up code, add ability to set up pager style through settings.sty…
Browse files Browse the repository at this point in the history
…le variable
  • Loading branch information
Martin Barreto committed Jan 22, 2016
1 parent 0ce8b56 commit 8945799
Show file tree
Hide file tree
Showing 15 changed files with 331 additions and 187 deletions.
22 changes: 19 additions & 3 deletions Example/Example/BarExampleViewController.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
//
// BarExampleViewController.swift
// Example
// XLPagerTabStrip ( https://github.com/xmartlabs/XLPagerTabStrip )
//
// Copyright (c) 2016 Xmartlabs ( http://xmartlabs.com )
//
//
// Created by Santiago on 1/20/16.
// 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
Expand Down
28 changes: 22 additions & 6 deletions Example/Example/ButtonBarExampleViewController.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
// ButtonBarExampleViewControlle.swift
// XLPagerTabStrip ( https://github.com/xmartlabs/XLPagerTabStrip )
//
// ButtonBarExampleViewController.swift
// Example
// Copyright (c) 2016 Xmartlabs ( http://xmartlabs.com )
//
// Created by Santiago on 1/21/16.
//
// 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

public class ButtonBarExampleViewControlle: ButtonBarPagerTabStripViewController {

var isReload = false

public override func viewDidLoad() {
Expand Down Expand Up @@ -39,11 +56,10 @@ public class ButtonBarExampleViewControlle: ButtonBarPagerTabStripViewController
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
var childViewControllers = [child_1, child_2, child_3, child_4, child_6, child_7, child_8]

for (index, _) in childViewControllers.enumerate(){
let nElements = count - index
let nElements = childViewControllers.count - index
let n = (Int(arc4random()) % nElements) + index
if n != index{
swap(&childViewControllers[index], &childViewControllers[n])
Expand Down
26 changes: 21 additions & 5 deletions Example/Example/ChildExampleViewController.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
//
// ChildExampleViewController.swift
// Example
// XLPagerTabStrip ( https://github.com/xmartlabs/XLPagerTabStrip )
//
// Copyright (c) 2016 Xmartlabs ( http://xmartlabs.com )
//
//
// Created by Santiago on 1/18/16.
// 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
Expand All @@ -25,9 +41,9 @@ class ChildExampleViewController: UIViewController, PagerTabStripChildItem {
view.addConstraint(NSLayoutConstraint(item: label, attribute: .CenterY, relatedBy: .Equal, toItem: view, attribute: .CenterY, multiplier: 1, constant: -50))
}

// MARK: - XLPagerTabStripViewControllerDelegate
// MARK: - PagerTabStripChildItem

func childHeaderForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> ChildItemInfo {
return ChildItemInfo(title: "View", image: nil, highlightedImage: nil, color: .whiteColor())
return ChildItemInfo(title: "View", image: nil, highlightedImage: nil)
}
}
22 changes: 19 additions & 3 deletions Example/Example/NavButtonBarExampleViewController.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
//
// NavButtonBarExampleViewController.swift
// Example
// XLPagerTabStrip ( https://github.com/xmartlabs/XLPagerTabStrip )
//
// Copyright (c) 2016 Xmartlabs ( http://xmartlabs.com )
//
//
// Created by Santiago on 1/22/16.
// 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
Expand Down
22 changes: 19 additions & 3 deletions Example/Example/PostCell.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
//
// PostCell.swift
// Example
// XLPagerTabStrip ( https://github.com/xmartlabs/XLPagerTabStrip )
//
// Copyright (c) 2016 Xmartlabs ( http://xmartlabs.com )
//
//
// Created by Santiago on 1/18/16.
// 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

Expand Down
22 changes: 19 additions & 3 deletions Example/Example/ReloadExampleViewController.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
//
// ReloadExampleViewController.swift
// Example
// XLPagerTabStrip ( https://github.com/xmartlabs/XLPagerTabStrip )
//
// Copyright (c) 2016 Xmartlabs ( http://xmartlabs.com )
//
//
// Created by Santiago on 1/20/16.
// 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
import XLPagerTabStrip
Expand Down
31 changes: 27 additions & 4 deletions Example/Example/SegmentedExampleViewController.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
//
// SegmentedExampleViewController.swift
// Example
// XLPagerTabStrip ( https://github.com/xmartlabs/XLPagerTabStrip )
//
// Copyright (c) 2016 Xmartlabs ( http://xmartlabs.com )
//
//
// Created by Santiago on 1/19/16.
// 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

public class SegmentedExampleViewController: SegmentedPagerTabStripViewController {

var isReload = false

required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
// change segmented style
settings.style.segmentedControlColor = .whiteColor()
}

// MARK: - XLPagerTabStripViewControllerDataSource

override public func childViewControllersForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
Expand All @@ -24,7 +47,7 @@ public class SegmentedExampleViewController: SegmentedPagerTabStripViewControlle
return [child_1, child_2, child_3, child_4]
}

var childViewControllers = [child_1, child_2, child_3, child_4] as Array
var childViewControllers = [child_1, child_2, child_3, child_4]
let count = childViewControllers.count

for (index, _) in childViewControllers.enumerate(){
Expand Down
26 changes: 21 additions & 5 deletions Example/Example/TableChildExampleViewController.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
//
// TableChildExampleViewController.swift
// Example
// XLPagerTabStrip ( https://github.com/xmartlabs/XLPagerTabStrip )
//
// Copyright (c) 2016 Xmartlabs ( http://xmartlabs.com )
//
//
// Created by Santiago on 1/18/16.
// 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
Expand Down Expand Up @@ -40,9 +56,9 @@ class TableChildExampleViewController: UITableViewController, PagerTabStripChild
return cell
}

// MARK: - XLPagerTabStripChildItem
// MARK: - PagerTabStripChildItem

func childHeaderForPagerTabStripViewController(pagerTabStripController: PagerTabStripViewController) -> ChildItemInfo {
return ChildItemInfo(title: "Table View", image: nil, highlightedImage: nil, color: .whiteColor())
return ChildItemInfo(title: "Table View", image: nil, highlightedImage: nil)
}
}
27 changes: 21 additions & 6 deletions Example/Example/TwitterExampleViewController.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
//
// TwitterExampleViewController.swift
// Example
// XLPagerTabStrip ( https://github.com/xmartlabs/XLPagerTabStrip )
//
// Copyright (c) 2016 Xmartlabs ( http://xmartlabs.com )
//
//
// Created by Santiago on 1/22/16.
// 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
Expand Down Expand Up @@ -34,11 +50,10 @@ public class TwitterExampleViewController: TwitterPagerTabStripViewController {
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
var childViewControllers = [child_1, child_2, child_3, child_4, child_6, child_7, child_8]

for (index, _) in childViewControllers.enumerate(){
let nElements = count - index
let nElements = childViewControllers.count - index
let n = (Int(arc4random()) % nElements) + index
if n != index{
swap(&childViewControllers[index], &childViewControllers[n])
Expand Down
4 changes: 2 additions & 2 deletions Example/Storyboard.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15A284" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="ptL-BW-nEP">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="ptL-BW-nEP">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
Expand Down Expand Up @@ -51,7 +51,7 @@
</barButtonItem>
</navigationItem>
<connections>
<outlet property="containerView" destination="D5t-1q-KDh" id="EwQ-Ub-iYS"/>
<outlet property="containerView" destination="D5t-1q-KDh" id="sbr-x5-J1L"/>
<outlet property="segmentedControl" destination="31B-gy-WIH" id="TxS-id-BP5"/>
</connections>
</viewController>
Expand Down
4 changes: 2 additions & 2 deletions Sources/ButtonBarPagerTabStripViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,12 @@ public class ButtonBarPagerTabStripViewController: PagerTabStripViewController,
var collectionViewContentWidth: CGFloat = 0

for viewController in self.viewControllers {
let childController = viewController as? PagerTabStripChildItem
let childController = viewController as! PagerTabStripChildItem

let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.font = self.buttonBarView.labelFont!
label.text = childController?.childHeaderForPagerTabStripViewController(self).title
label.text = childController.childHeaderForPagerTabStripViewController(self).title
let labelSize = label.intrinsicContentSize()

let minimumCellWidth = labelSize.width + CGFloat(self.buttonBarView.leftRightMargin! * 2)
Expand Down
Loading

0 comments on commit 8945799

Please sign in to comment.