Skip to content

A container which easy to add children viewcontrollers and support horizontal scroll.

License

Notifications You must be signed in to change notification settings

interchen/ICPageViewController

Repository files navigation

ICPageViewController Build Status

A container which is easy to add children viewcontrollers and supports horizontal scroll.

Preview

screenshot

Create ICPageViewController instance

let pageViewController = ICPageViewController()
    
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    pageViewController.pageViewDelegate = self
    self.addChildViewController(pageViewController)
    self.view.addSubview(pageViewController.view)
    pageViewController.didMove(toParentViewController: self)
}

override func viewDidLayoutSubviews() {
    pageViewController.view.frame = self.view.bounds
}

Implement ICPageViewControllerDelegate

func numberOfItems(in pageViewController: ICPageViewController) -> Int {
    return 10
}

func pageViewController(_ pageViewController: ICPageViewController, viewControllerForItemAt index: Int) -> UIViewController {
    let viewController = self.storyboard?.instantiateViewController(withIdentifier: "demoViewController") as? SubViewController
    viewController?.label = "sub viewcontroller \(index)"
    switch index {
    case 0:
        viewController?.view.backgroundColor = .blue

    case 1:
        viewController?.view.backgroundColor = .red

    case 2:
        viewController?.view.backgroundColor = .gray

    default:
        viewController?.view.backgroundColor = .white
    }
    return viewController!
}

Cocoapods

pod 'ICPageViewController'

Don't forget to star if you think this is helpful.

如果这个项目帮到你了,Star 一下再走呗

About

A container which easy to add children viewcontrollers and support horizontal scroll.

Resources

License

Stars

Watchers

Forks

Packages

No packages published