Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registering cells from nib. #227

Merged
merged 1 commit into from
Aug 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CalendarExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ViewController: UIViewController {
// Create an instance of PagingViewController where CalendarItem
// is set as the generic type.
let pagingViewController = PagingViewController<CalendarItem>()
pagingViewController.menuItemClass = CalendarPagingCell.self
pagingViewController.menuItemSource = .class(type: CalendarPagingCell.self)
pagingViewController.menuItemSize = .fixed(width: 48, height: 58)
pagingViewController.textColor = UIColor(red: 95/255, green: 102/255, blue: 108/255, alpha: 1)
pagingViewController.selectedTextColor = UIColor(red: 117/255, green: 111/255, blue: 216/255, alpha: 1)
Expand Down
2 changes: 1 addition & 1 deletion IconsExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ViewController: UIViewController {
super.viewDidLoad()

let pagingViewController = PagingViewController<IconItem>()
pagingViewController.menuItemClass = IconPagingCell.self
pagingViewController.menuItemSource = .class(type: IconPagingCell.self)
pagingViewController.menuItemSize = .fixed(width: 60, height: 60)
pagingViewController.textColor = UIColor(red: 0.51, green: 0.54, blue: 0.56, alpha: 1)
pagingViewController.selectedTextColor = UIColor(red: 0.14, green: 0.77, blue: 0.85, alpha: 1)
Expand Down
4 changes: 4 additions & 0 deletions Parchment.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
95F2CCA61E395762003C973E /* Parchment.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3EA04A4B1C53BFE40054E5E0 /* Parchment.framework */; };
95F2CCA71E395762003C973E /* Parchment.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3EA04A4B1C53BFE40054E5E0 /* Parchment.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
95FE3AF91FFEDBCE00E6F2AD /* PagingDistance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95FE3AF81FFEDBCE00E6F2AD /* PagingDistance.swift */; };
E9D1BE1E211E409400E86B72 /* PagingMenuItemSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9D1BE1D211E409400E86B72 /* PagingMenuItemSource.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -412,6 +413,7 @@
95E4BA6F1FF15E84008871A3 /* PagingViewControllerDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PagingViewControllerDataSource.swift; sourceTree = "<group>"; };
95E4BA711FF15EFE008871A3 /* IndexedPagingDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IndexedPagingDataSource.swift; sourceTree = "<group>"; };
95FE3AF81FFEDBCE00E6F2AD /* PagingDistance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PagingDistance.swift; sourceTree = "<group>"; };
E9D1BE1D211E409400E86B72 /* PagingMenuItemSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PagingMenuItemSource.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -539,6 +541,7 @@
955444C11FC9CD19001EC26B /* PagingMenuTransition.swift */,
955444BD1FC9CCEC001EC26B /* PagingSelectedScrollPosition.swift */,
3E4090991C88BCC900800E22 /* PagingState.swift */,
E9D1BE1D211E409400E86B72 /* PagingMenuItemSource.swift */,
);
path = Enums;
sourceTree = "<group>";
Expand Down Expand Up @@ -1185,6 +1188,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
E9D1BE1E211E409400E86B72 /* PagingMenuItemSource.swift in Sources */,
3EF3C1E31CA0870E00CDFE26 /* FixedPagingViewController.swift in Sources */,
95868C34200412DE004B392B /* Tween.swift in Sources */,
95A52A151FF81F70002A2ED4 /* PagingLayout.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions Parchment/Classes/PagingOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import UIKit

public class PagingOptions {
public var menuItemSize: PagingMenuItemSize
public var menuItemClass: PagingCell.Type
public var menuItemSource: PagingMenuItemSource
public var menuItemSpacing: CGFloat
public var menuInsets: UIEdgeInsets
public var menuHorizontalAlignment: PagingMenuHorizontalAlignment
Expand Down Expand Up @@ -54,7 +54,7 @@ public class PagingOptions {
menuItemSize = .sizeToFit(minWidth: 150, height: 40)
menuTransition = .scrollAlongside
menuInteraction = .scrolling
menuItemClass = PagingTitleCell.self
menuItemSource = .class(type: PagingTitleCell.self)
menuInsets = UIEdgeInsets.zero
menuItemSpacing = 0
menuHorizontalAlignment = .left
Expand Down
16 changes: 12 additions & 4 deletions Parchment/Classes/PagingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ open class PagingViewController<T: PagingItem>:

/// The class type for the menu item. Override this if you want
/// your own custom menu items. _Default: PagingTitleCell.self_
public var menuItemClass: PagingCell.Type {
get { return options.menuItemClass }
set { options.menuItemClass = newValue }
public var menuItemSource: PagingMenuItemSource {
get { return options.menuItemSource }
set { options.menuItemSource = newValue }
}

/// Determine the spacing between the menu items. _Default: 0_
Expand Down Expand Up @@ -431,7 +431,15 @@ open class PagingViewController<T: PagingItem>:
collectionView.showsHorizontalScrollIndicator = false
collectionView.delegate = self
collectionView.dataSource = self
collectionView.register(options.menuItemClass, forCellWithReuseIdentifier: PagingCellReuseIdentifier)

switch options.menuItemSource {
case .class(let type):
collectionView.register(type, forCellWithReuseIdentifier: PagingCellReuseIdentifier)

case .nib(let nib):
collectionView.register(nib, forCellWithReuseIdentifier: PagingCellReuseIdentifier)
}


configureMenuInteraction()
configureContentInteraction()
Expand Down
6 changes: 6 additions & 0 deletions Parchment/Enums/PagingMenuItemSource.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Foundation

public enum PagingMenuItemSource {
case `class`(type: PagingCell.Type)
case nib(nib: UINib)
}
2 changes: 1 addition & 1 deletion UnplashExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class ViewController: UIViewController {
super.viewDidLoad()

let pagingViewController = PagingViewController<ImageItem>()
pagingViewController.menuItemClass = ImagePagingCell.self
pagingViewController.menuItemSource = .class(type: ImagePagingCell.self)
pagingViewController.menuItemSize = .fixed(width: 70, height: 70)
pagingViewController.menuItemSpacing = 8
pagingViewController.menuInsets = UIEdgeInsets(top: 12, left: 18, bottom: 12, right: 18)
Expand Down