A UIKit container with swipeable pages and a toolbar tab bar above or below the content.
Use it for related screens that share a navigation stack and support both horizontal swipes and tab taps. It has no overflow or “More” tab. Horizontal gestures inside a page may compete with page swiping. It does not create a separate navigation stack for each tab.
Online documentation · Changelog
- iOS/iPadOS 17 or later, or Mac Catalyst. Native AppKit macOS is not supported.
- Swift tools 5.9 or later, in Swift 5 language mode.
- Xcode 26 or later, because the source references iOS 26 SDK APIs behind availability checks.
- Configure and use the container on the main actor.
- No external package dependencies.
Add https://github.com/LittleGreenViper/SwipeTabController.git in Xcode's Package Dependencies, then link the
SwipeTabController library product and import SwipeTabController.
The implementation also fits in one Swift file,
which you can add directly to your UIKit project. The repository includes an Xcode static-library target as another
integration option. With Carthage, use github "LittleGreenViper/SwipeTabController" to fetch the source;
the supplied Xcode target is a static library, not a prebuilt framework or XCFramework distribution.
import UIKit
import SwipeTabController
final class MyTabs: LGV_SwipeTabViewController {
override var generatedViewControllers: [any LGV_SwipeTabViewControllerType] {
["Inbox", "Settings"].map { title in
let page = LGV_SwipeTab_Base_ViewController()
page.tabBarItem = UITabBarItem(title: title, image: nil, tag: 0)
page.navigationItem.title = title
page.view.backgroundColor = .systemBackground
return page
}
}
}Present MyTabs, or push it onto an existing navigation stack. Set toolbarOnTop = true before loading for a top toolbar.
Set textOnRight = true to put text beside each image, respecting layout direction.
Every page must conform to LGV_SwipeTabViewControllerType and return a non-nil myTabItem before the container loads.
The supplied base class provides a weak owner reference and uses tabBarItem when it has an image or a nonempty title.
A page's viewDidLoad() is too late to configure its initial tab item.
The page collection is fixed when the container loads. generatedViewControllers is read once, and duplicate instances,
already-parented or already-owned pages, and missing tab items are skipped. The initially selected child is installed
after the container appears in a window, so it may not yet exist immediately after loadViewIfNeeded().
Set the container and page classes and storyboard IDs in Interface Builder. In the container subclass:
override func viewDidLoad() {
discoversViewControllersFromSegues = false
viewControllerIDs = ["01-Inbox", "02-Settings"]
super.viewDidLoad()
}IDs are deduplicated and sorted using Swift string ordering; generated pages follow in their supplied order.
Every nonempty ID must exist in the container's storyboard. A missing ID raises an Objective-C exception, which Swift
do/catch cannot catch. Without a storyboard, IDs are ignored.
Legacy segue discovery remains enabled by default. It reads segue identifiers from undocumented UIKit storage and
combines them with viewControllerIDs. Each identifier must match a destination storyboard ID. SwipeTabSegue is a
placeholder custom segue; the container never performs it. This path is not a supported Apple API, and future compatibility
or App Store acceptance cannot be guaranteed. Disable discovery and list every page ID explicitly to avoid that dependency.
Use selectedViewControllerIndex = index or selectViewController(at: index); both select the corresponding page.
Before loading, a nonnegative index requests the initial page without forcing loading. An invalid initial index falls back
to zero. After loading, invalid indices are ignored. During a transition, the latest request is queued, and the selected
index stays at the last committed page. Selecting the current page does nothing.
beforeSwipeCallback runs before a programmatic transition or interactive swipe. afterSwipeCallback runs after a new
page is selected and navigation and toolbar state have been updated. Cancelled swipes do not call the after callback.
Programmatic selections install the page synchronously and slide snapshots, with selection committed after the
animation completes. Appearance callbacks can run before that commit. Pages that reserve horizontal gestures for
row actions should defer disabling paging until after viewDidAppear returns, and restore it in viewWillDisappear.
Initial installation and no-op selections do not call either callback. Both run on the main actor, and requests from
callbacks are queued. Capture owners weakly when appropriate; the container retains its callbacks.
Call reloadTabBarItems() after changing a tab title, image, selected image, badge, enabled state, accessibility text,
view tint, or textOnRight. Nil or empty badges are hidden. Original-rendering images preserve their colors; other images
and titles use secondary-label gray when selected and the view tint otherwise. Selection has no background bubble.
Disabled tab items prevent taps but remain reachable through swiping and programmatic selection.
Supply an accessibility label for image-only tabs. Selected state and badge values are exposed on the toolbar buttons.
Titles, accessibility labels, and hints prefixed with SLUG- are localized in place using the main bundle's default
Localizable.strings table. Other strings remain literal. Reloading does not replace or reorder pages.
Set each page's own navigation title and left and right buttons. Selection copies these to the container and ordinary
ancestors, stopping before navigation and tab bar controllers. Empty button groups clear the previous page's buttons.
Button groups installed by the container or an ancestor, such as a persistent Main Menu, take precedence over page
buttons on that side. Only empty groups or groups still containing the last propagated page buttons are replaced.
Later changes to a selected page's navigation item are not observed automatically. Pages can push using
myMainNavigationController; the supplied base class also exposes this through navigationController.
Override the open styleToolbar() method to customize toolbar appearance. Set toolbarOnTop before loading, since
changing it later does not rebuild constraints. Keep the page controller's delegate, data source, and selection managed
by the container.
The source uses block HeaderDoc comments for Xcode Quick Help and DocC. In Xcode, select the library scheme and use Product → Build Documentation. The catalog includes setup examples and selection and customization.
Open the Xcode project and select SwipeTabController or SwipeTabControllerTestHarness, then run
Product → Test on an iOS Simulator. The tests run inside the harness app so UIKit animations have a real app host.
The SwipeTabControllerTestHarness scheme also provides an interactive app. Its -SPM variant normally
uses the remote package; apply a local package override when checking uncommitted changes.
See verification notes for automated coverage and manual checks.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

