gitmyhub

XLPagerTabStrip

Swift ★ 7.0k updated 2y ago

Android PagerTabStrip for iOS.

XLPagerTabStrip is an iOS library written in Swift that lets you build tabbed navigation inside your app, the kind where you can swipe left and right between different screens while a visual indicator tracks which tab you are on. The pattern is common in popular apps: Instagram uses it for profile sections, YouTube uses it to separate tabs like Home, Trending, and Subscriptions, and Spotify uses a similar layout for library views. This library brings that same interaction to any iOS app.

The library gives you four ready-made styles for the tab indicator. The Button Bar style shows labeled buttons along the top, which is the most widely used layout. The Bar style skips labels entirely and just shows a sliding underline. The Twitter style, modeled after an older version of the Twitter app, places the indicator differently. The Segmented style uses a standard iOS segmented control as the selector. All four styles share the same underlying logic, so swapping between them is mostly a matter of choosing which base class your view controller extends from.

To use it, you create a view controller that inherits from one of those four base classes, connect a scroll view to the container outlet in your storyboard, and then override a single method to return the list of child view controllers you want to display. Each child screen tells the tab strip what label or image to show for its tab by conforming to a small protocol with one required method. That is the full setup for a basic integration.

Customization options let you control how the tab indicator moves during a swipe. You can choose between a progressive style, where the indicator slides smoothly as your finger moves, or a common style, where it snaps into place at the halfway point of the transition. There are also detailed options for the Button Bar style covering cell width, spacing, colors, and font.

The library is available through CocoaPods and Carthage, the two standard iOS dependency managers, and requires Swift 5. The authors also maintain a separate SwiftUI-based version called PagerTabStripView for projects that use SwiftUI instead of UIKit.