LGV_SwipeTabViewController

@IBDesignable
@MainActor
open class LGV_SwipeTabViewController : UIViewController
extension LGV_SwipeTabViewController: UIPageViewControllerDataSource
extension LGV_SwipeTabViewController: UIPageViewControllerDelegate

This implements an instance of a UIPageViewController, as well as a UIToolbar instance. The toolbar acts in the same manner as a UITabBar, and is displayed either below (default), or above the page view controller.

The page view controller provides the “swipe” action, and the toolbar provides the “tab bar” action.

This results in behavior like Android. In Android, you can swipe between tabs, as well as select them directly.

You can have the “tab bar” displayed above the page, as in Android, or below (default), as in iOS.

This is a lot more limited than a real UITabBarController, but it should be useful for most implementations. You do have access to both the page view controller, and the toolbar, if you want to do more customization.

It will allow you to propagate a navigation controller, applied to the container, into internal views. That’s always an annoying issue with UITabBarController. You need to remember that the tab controller is hosting the navigation bar; not your embedded controller.

Private Button Class for Toolbar Items

  • This is true (default is false), if we want the “Tab Bar” to show up on top of the screen (as opposed to the default bottom).

    Note

    This shouldn’t be changed after the view is loaded.

    Declaration

    Swift

    @IBInspectable
    @MainActor
    public var toolbarOnTop: Bool
  • This is true (default is false), if we want the “Tab Bar” items to show the text on the right of each item (as opposed to the default bottom).

    Note

    This shouldn’t be changed after the view is loaded.

    Declaration

    Swift

    @IBInspectable
    @MainActor
    public var textOnRight: Bool
  • The zero-based selected controller. Default is 0.

    Declaration

    Swift

    @IBInspectable
    @MainActor
    public var selectedViewControllerIndex: Int { get set }
  • This needs to be populated, if you want to add view controllers programmatically, but using the storyboard. This returns a runtime-generated list of storyboard IDs of classes that we will instantiate for each of our tabbed controllers.

    Note

    It’s very important that this property be set BEFORE calling super.viewDidLoad().

    Declaration

    Swift

    @MainActor
    public var viewControllerIDs: [String]
  • This needs to be overridden, if you want to add view controllers programmatically, without using the storyboard. This returns a concrete array of instantiated and loaded view controller instances. If we are also generating via IDs (storyboard), these will be appended to the existing list, in the order prescribed, here.

    Note

    Declared here as “open,” so it can be overridden.

    Declaration

    Swift

    @MainActor
    open var generatedViewControllers: [any LGV_SwipeTabViewControllerType] { get }

Public Computed Properties

  • This is the page view controller that will allow swiped tabs.

    Declaration

    Swift

    @MainActor
    weak var pageViewController: UIPageViewController? { get }
  • This is the toolbar, at the top or bottom.

    Declaration

    Swift

    @MainActor
    weak var toolbar: UIToolbar? { get }
  • Accessor for the referenced view controllers.

    Declaration

    Swift

    @MainActor
    var referencedViewControllers: [any LGV_SwipeTabViewControllerType] { get }

Base Class Overrides

  • Called when the view hierarchy has been set up.

    Declaration

    Swift

    @MainActor
    open override func viewDidLoad()
  • Called, when the layout will be changed.

    Declaration

    Swift

    @MainActor
    open override func viewWillLayoutSubviews()

Public Instance Methods

  • Override this, to provide your own toolbar styling. Default, is a completely transparent toolbar.

    Declaration

    Swift

    @MainActor
    func styleToolbar()
  • Called to select a specific view controller.

    Declaration

    Swift

    @MainActor
    func selectViewController(at inIndex: Int)

UIPageViewControllerDataSource Conformance

  • Called to provide a new view controller, when swiping.

    Declaration

    Swift

    @MainActor
    public func pageViewController(_ inController: UIPageViewController, viewControllerBefore inNextViewController: UIViewController) -> UIViewController?

    Parameters

    inController

    The page view controller (ignored).

    inNextViewController

    The view controller for the timer that will be AFTER ours

  • Called to provide a new view controller, when swiping.

    Declaration

    Swift

    @MainActor
    public func pageViewController(_ inController: UIPageViewController, viewControllerAfter inPrevViewController: UIViewController) -> UIViewController?

    Parameters

    inController

    The page view controller (ignored).

    inPrevViewController

    The view controller for the timer that will be BEFORE ours

UIPageViewControllerDelegate Conformance

  • Called when a swipe has completed.

    Declaration

    Swift

    @MainActor
    public func pageViewController(_ inController: UIPageViewController, didFinishAnimating: Bool, previousViewControllers: [UIViewController], transitionCompleted inCompleted: Bool)

    Parameters

    inController

    The page view controller (ignored).

    didFinishAnimating

    True, if the animation completed (ignored).

    previousViewControllers

    The previous view controllers (ignored).

    inCompleted

    True, if the transition completed (ignored).