Swiftpack.co -  uias/Pageboy as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
๐Ÿ“– A simple, highly informative page view controller
.package(url: "https://github.com/uias/Pageboy.git", from: "3.6.2")


TL;DR UIPageViewController done properly.

โญ๏ธ Features

  • โ˜‘ Simplified data source management & enhanced delegation.
  • โ˜‘ Dynamically insert & remove pages.
  • โ˜‘ Infinite scrolling support.
  • โ˜‘ Automatic timer-based page transitioning.
  • โ˜‘ Support for custom animated page transitions.

๐Ÿ“‹ Requirements

Pageboy requires iOS 9 / tvOS 10; and is compatible with Swift 5.

๐Ÿ“ฒ Installation

Swift Package Manager

Pageboy is compatible with Swift Package Manager and can be integrated via Xcode.


Pageboy is also available through CocoaPods:

pod 'Pageboy', '~> 3.6'


Pageboy is also available through Carthage:

github "uias/Pageboy" ~> 3.6

๐Ÿš€ Usage

The Basics

  1. Create an instance of a PageboyViewController and provide it with a PageboyViewControllerDataSource.
class PageViewController: PageboyViewController, PageboyViewControllerDataSource {

    override func viewDidLoad() {
	self.dataSource = self
  1. Implement the PageboyViewControllerDataSource functions.
func numberOfViewControllers(in pageboyViewController: PageboyViewController) -> Int {
    return viewControllers.count

func viewController(for pageboyViewController: PageboyViewController,
                    at index: PageboyViewController.PageIndex) -> UIViewController? {
    return viewControllers[index]

func defaultPage(for pageboyViewController: PageboyViewController) -> PageboyViewController.Page? {
    return nil


The delegate functions provided by a PageboyViewController are much more reliable and useful than what a raw UIPageViewController provides. You can use them to find out exactly where the current page is, and when it's moved, where it's headed.


About to embark on a transition to a new page.

func pageboyViewController(_ pageboyViewController: PageboyViewController,
                           willScrollToPageAt index: Int,
                           direction: NavigationDirection,
                           animated: Bool)


Scrolled to a relative position along the way transitioning to a new page.

func pageboyViewController(_ pageboyViewController: PageboyViewController,
                           didScrollTo position: CGPoint,
                           direction: NavigationDirection,
                           animated: Bool)


Successfully completed a scroll transition to a page.

func pageboyViewController(_ pageboyViewController: PageboyViewController,
                           didScrollToPageAt index: Int,
                           direction: NavigationDirection,
                           animated: Bool)


Child view controllers have been reloaded.

func pageboyViewController(_ pageboyViewController: PageboyViewController,
                           didReloadWith currentViewController: UIViewController,
                           currentPageIndex: PageIndex)


You can navigate programmatically through a PageboyViewController using scrollToPage():

pageViewController.scrollToPage(.next, animated: true)
  • Infinite scrolling can be enabled with .isInfiniteScrollEnabled.
  • Interactive scrolling can also be controlled with .isScrollEnabled.

Insertion & Deletion

Pageboy provides the ability to insert and delete pages dynamically in the PageboyViewController.

func insertPage(at index: PageIndex, then updateBehavior: PageUpdateBehavior)
func deletePage(at index: PageIndex, then updateBehavior: PageUpdateBehavior)

This behaves similarly to the insertion of rows in UITableView, in the fact that you have to update the data source prior to calling any of the update functions.


let index = 2
viewControllers.insert(UIViewController(), at: index)
pageViewController.insertPage(at: index)

The default behavior after inserting or deleting a page is to scroll to the update location, this however can be configured by passing a PageUpdateBehavior value other than .scrollToUpdate.

โšก๏ธ Other Extras

  • reloadData() - Reload the view controllers in the page view controller. (Reloads the data source).
  • .navigationOrientation - Whether to orientate the pages horizontally or vertically.
  • .currentViewController - The currently visible view controller if it exists.
  • .currentPosition - The exact current relative position of the page view controller.
  • .currentIndex - The index of the currently visible page.
  • .parentPageboy - Access the immediate parent PageboyViewController from any child view controller.

Animated Transitions

Pageboy also provides custom transition support for animated transitions. This can be customized via the .transition property on PageboyViewController.

pageboyViewController.transition = Transition(style: .push, duration: 1.0)

Note: By default this is set to nil, which uses the standard animation provided by UIPageViewController.

Auto Scrolling

PageboyAutoScroller is available to set up timer based automatic scrolling of the PageboyViewController:


Support for custom intermission duration and other scroll behaviors is also available.

๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป About

โค๏ธ Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/uias/Pageboy.

๐Ÿ‘ฎ๐Ÿปโ€โ™‚๏ธ License

The library is available as open source under the terms of the MIT License.


Stars: 1593
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jackโ€™d and SCRUFF. We are two of the worldโ€™s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

41 weeks ago


  • Issue where page positional detection would fail on tvOS.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API