Easy way to use UIScrollView page
CocoaPods is a dependency manager for Cocoa projects.
Specify PageKit into your project's Podfile:
platform :ios, '8.0'
use_frameworks!
target '<Your App Target>' do
pod 'PageKit', :git => 'git@github.com:XWJACK/PageKit.git'
end
Then run the following command:
$ pod install
Carthage is a simple, decentralized dependency manager for Cocoa.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate PageKit into your Xcode project using Carthage, specify it in your Cartfile
:
github "XWJACK/PageKit"
Run carthage update
to build the framework and drag the built PageKit.framework
into your Xcode project.
Using same with UITableView
.
class GuidePageViewController: UIViewController, GuidePageDatasource {
let guidePage = GuidePage()
override func viewDidLoad() {
super.viewDidLoad()
guidePage.dataSource = self
guidePage.register(TestPageImageView.self)
guidePage.register(TestPageViewController.self)
view.addSubview(guidePage)
guidePage.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
}
}
func numberOfPages() -> Int {
return 5
}
func guidePage(_ guidePage: GuidePage, pageForIndexAt index: Int) -> Page {
if index % 2 == 0, let page = guidePage.dequeueReusablePage(withIdentifier: TestPageImageView.reuseIdentifier) as? UIImageView {
page.image = #imageLiteral(resourceName: "origin_background0")
return page
} else if let page = guidePage.dequeueReusablePage(withIdentifier: TestPageViewController.reuseIdentifier) as? TestPageViewController {
return page
} else {
let view = UIImageView()
view.backgroundColor = .red
return view
}
}
}