diff --git a/.gitignore b/.gitignore index ec58845f..091b6169 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ ## Build generated build/ DerivedData +.swiftpm/ ## Various settings *.pbxuser @@ -51,4 +52,4 @@ playground.xcworkspace Carthage/Build -.swift-version \ No newline at end of file +.swift-version diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Package.swift b/Package.swift new file mode 100644 index 00000000..0a328eba --- /dev/null +++ b/Package.swift @@ -0,0 +1,26 @@ +// swift-tools-version:5.3 + +import PackageDescription + +let package = Package( + name: "XLPagerTabStrip", + platforms: [ + .iOS(.v9) + ], + products: [ + .library( + name: "XLPagerTabStrip", + targets: ["XLPagerTabStrip"] + ) + ], + targets: [ + .target( + name: "FXPageControl", + publicHeadersPath: "." + ), + .target( + name: "XLPagerTabStrip", + dependencies: ["FXPageControl"] + ), + ] +) diff --git a/Sources/FXPageControl.h b/Sources/FXPageControl/FXPageControl.h similarity index 100% rename from Sources/FXPageControl.h rename to Sources/FXPageControl/FXPageControl.h diff --git a/Sources/FXPageControl.m b/Sources/FXPageControl/FXPageControl.m similarity index 100% rename from Sources/FXPageControl.m rename to Sources/FXPageControl/FXPageControl.m diff --git a/Sources/BarPagerTabStripViewController.swift b/Sources/XLPagerTabStrip/BarPagerTabStripViewController.swift similarity index 100% rename from Sources/BarPagerTabStripViewController.swift rename to Sources/XLPagerTabStrip/BarPagerTabStripViewController.swift diff --git a/Sources/BarView.swift b/Sources/XLPagerTabStrip/BarView.swift similarity index 99% rename from Sources/BarView.swift rename to Sources/XLPagerTabStrip/BarView.swift index 1183524d..843b8bc3 100644 --- a/Sources/BarView.swift +++ b/Sources/XLPagerTabStrip/BarView.swift @@ -23,6 +23,7 @@ // THE SOFTWARE. import Foundation +import UIKit open class BarView: UIView { diff --git a/Sources/BaseButtonBarPagerTabStripViewController.swift b/Sources/XLPagerTabStrip/BaseButtonBarPagerTabStripViewController.swift similarity index 99% rename from Sources/BaseButtonBarPagerTabStripViewController.swift rename to Sources/XLPagerTabStrip/BaseButtonBarPagerTabStripViewController.swift index 68684ac4..1c78b267 100644 --- a/Sources/BaseButtonBarPagerTabStripViewController.swift +++ b/Sources/XLPagerTabStrip/BaseButtonBarPagerTabStripViewController.swift @@ -23,6 +23,7 @@ // THE SOFTWARE. import Foundation +import UIKit open class BaseButtonBarPagerTabStripViewController: PagerTabStripViewController, PagerTabStripDataSource, PagerTabStripIsProgressiveDelegate, UICollectionViewDelegate, UICollectionViewDataSource { diff --git a/Sources/ButtonBarPagerTabStripViewController.swift b/Sources/XLPagerTabStrip/ButtonBarPagerTabStripViewController.swift similarity index 89% rename from Sources/ButtonBarPagerTabStripViewController.swift rename to Sources/XLPagerTabStrip/ButtonBarPagerTabStripViewController.swift index 36e008d6..e9fd1eec 100644 --- a/Sources/ButtonBarPagerTabStripViewController.swift +++ b/Sources/XLPagerTabStrip/ButtonBarPagerTabStripViewController.swift @@ -23,6 +23,35 @@ // THE SOFTWARE. import Foundation +import UIKit + + +extension Foundation.Bundle { + /// Returns the resource bundle associated with the current Swift module. + static var resourceBundle: Bundle = { + let candidates = [ + // Bundle should be present here when the package is linked into an App. + Bundle.main.resourceURL, + + // Bundle should be present here when the package is linked into a framework. + Bundle(for: ButtonBarViewCell.self).resourceURL, + + // For command-line tools. + Bundle.main.bundleURL, + ] + + for candidate in candidates { + let bundleNames = ["XLPagerTabStrip", "XLPagerTabStrip_XLPagerTabStrip"] + for name in bundleNames { + let bundlePath = candidate?.appendingPathComponent(name + ".bundle") + if let bundle = bundlePath.flatMap(Bundle.init(url:)) { + return bundle + } + } + } + fatalError("unable to find bundle named XLPagerTabStrip_XLPagerTabStrip") + }() +} public enum ButtonBarItemSpec { @@ -93,37 +122,32 @@ open class ButtonBarPagerTabStripViewController: PagerTabStripViewController, Pa open override func viewDidLoad() { super.viewDidLoad() - - var bundle = Bundle(for: ButtonBarViewCell.self) - if let resourcePath = bundle.path(forResource: "XLPagerTabStrip", ofType: "bundle") { - if let resourcesBundle = Bundle(path: resourcePath) { - bundle = resourcesBundle - } - } + + let bundle = Bundle.resourceBundle buttonBarItemSpec = .nibFile(nibName: "ButtonCell", bundle: bundle, width: { [weak self] (childItemInfo) -> CGFloat in - let label = UILabel() - label.translatesAutoresizingMaskIntoConstraints = false - label.font = self?.settings.style.buttonBarItemFont - label.text = childItemInfo.title - let labelSize = label.intrinsicContentSize - return labelSize.width + (self?.settings.style.buttonBarItemLeftRightMargin ?? 8) * 2 + let label = UILabel() + label.translatesAutoresizingMaskIntoConstraints = false + label.font = self?.settings.style.buttonBarItemFont + label.text = childItemInfo.title + let labelSize = label.intrinsicContentSize + return labelSize.width + (self?.settings.style.buttonBarItemLeftRightMargin ?? 8) * 2 }) let buttonBarViewAux = buttonBarView ?? { - let flowLayout = UICollectionViewFlowLayout() - flowLayout.scrollDirection = .horizontal - let buttonBarHeight = settings.style.buttonBarHeight ?? 44 - let buttonBar = ButtonBarView(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: buttonBarHeight), collectionViewLayout: flowLayout) - buttonBar.backgroundColor = .orange - buttonBar.selectedBar.backgroundColor = .black - buttonBar.autoresizingMask = .flexibleWidth - var newContainerViewFrame = containerView.frame - newContainerViewFrame.origin.y = buttonBarHeight - newContainerViewFrame.size.height = containerView.frame.size.height - (buttonBarHeight - containerView.frame.origin.y) - containerView.frame = newContainerViewFrame - return buttonBar - }() + let flowLayout = UICollectionViewFlowLayout() + flowLayout.scrollDirection = .horizontal + let buttonBarHeight = settings.style.buttonBarHeight ?? 44 + let buttonBar = ButtonBarView(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: buttonBarHeight), collectionViewLayout: flowLayout) + buttonBar.backgroundColor = .orange + buttonBar.selectedBar.backgroundColor = .black + buttonBar.autoresizingMask = .flexibleWidth + var newContainerViewFrame = containerView.frame + newContainerViewFrame.origin.y = buttonBarHeight + newContainerViewFrame.size.height = containerView.frame.size.height - (buttonBarHeight - containerView.frame.origin.y) + containerView.frame = newContainerViewFrame + return buttonBar + }() buttonBarView = buttonBarViewAux if buttonBarView.superview == nil { diff --git a/Sources/ButtonBarView.swift b/Sources/XLPagerTabStrip/ButtonBarView.swift similarity index 100% rename from Sources/ButtonBarView.swift rename to Sources/XLPagerTabStrip/ButtonBarView.swift diff --git a/Sources/ButtonBarViewCell.swift b/Sources/XLPagerTabStrip/ButtonBarViewCell.swift similarity index 100% rename from Sources/ButtonBarViewCell.swift rename to Sources/XLPagerTabStrip/ButtonBarViewCell.swift diff --git a/Sources/IndicatorInfo.swift b/Sources/XLPagerTabStrip/IndicatorInfo.swift similarity index 99% rename from Sources/IndicatorInfo.swift rename to Sources/XLPagerTabStrip/IndicatorInfo.swift index 146eb9a5..e5fff108 100644 --- a/Sources/IndicatorInfo.swift +++ b/Sources/XLPagerTabStrip/IndicatorInfo.swift @@ -23,6 +23,7 @@ // THE SOFTWARE. import Foundation +import UIKit public struct IndicatorInfo { diff --git a/Sources/PagerTabStripBehaviour.swift b/Sources/XLPagerTabStrip/PagerTabStripBehaviour.swift similarity index 100% rename from Sources/PagerTabStripBehaviour.swift rename to Sources/XLPagerTabStrip/PagerTabStripBehaviour.swift diff --git a/Sources/PagerTabStripError.swift b/Sources/XLPagerTabStrip/PagerTabStripError.swift similarity index 100% rename from Sources/PagerTabStripError.swift rename to Sources/XLPagerTabStrip/PagerTabStripError.swift diff --git a/Sources/PagerTabStripViewController.swift b/Sources/XLPagerTabStrip/PagerTabStripViewController.swift similarity index 99% rename from Sources/PagerTabStripViewController.swift rename to Sources/XLPagerTabStrip/PagerTabStripViewController.swift index 9aedb7d6..902706cf 100644 --- a/Sources/PagerTabStripViewController.swift +++ b/Sources/XLPagerTabStrip/PagerTabStripViewController.swift @@ -23,6 +23,7 @@ // THE SOFTWARE. import Foundation +import UIKit // MARK: Protocols diff --git a/Sources/ButtonCell.xib b/Sources/XLPagerTabStrip/Resources/ButtonCell.xib similarity index 87% rename from Sources/ButtonCell.xib rename to Sources/XLPagerTabStrip/Resources/ButtonCell.xib index 7025bc70..94ca345f 100644 --- a/Sources/ButtonCell.xib +++ b/Sources/XLPagerTabStrip/Resources/ButtonCell.xib @@ -1,17 +1,15 @@ - - - - + + - + - + @@ -19,7 +17,7 @@