欢迎光临
我们一直在努力

横向滚动多个 ViewController

建站超值云服务器,限时71元/月

横向滚动多个 ViewController

项目介绍:

ICPageViewController Build Status

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

Github

https://github.com/interchen/ICPageViewController

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.

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 横向滚动多个 ViewController
分享到: 更多 (0)