Description
PagerTabStripView is the first pager view built in pure SwiftUI. It provides a component to create interactive pager views which contains child views. It allows the user to switch between your views either by swiping or tapping a tab bar item.
Unlike Apple's TabView it provides:
- Flexible way to fully customize pager tab views.
- Each pagerTabItem view can be of different type.
- Bar that contains pager tab item is placed on top.
- Indicator view indicates selected child view.
- onPageAppear callback to easily trigger actions when page is selected.
- Ability to update pagerTabItem according to highlighted, selected, normal state.
PagerTabStripView alternatives and similar libraries
Based on the "UI" category.
Alternatively, view PagerTabStripView alternatives based on common mentions on social networks and blogs.
-
IQKeyboardManager
Codeless drop-in universal library allows to prevent issues of keyboard sliding up and cover UITextField/UITextView. Neither need to write any code nor any setup required and much more. -
DZNEmptyDataSet
DISCONTINUED. A drop-in UITableView/UICollectionView superclass category for showing empty datasets whenever the view has no content to display -
SkeletonView
☠️ An elegant way to show users that something is happening and also prepare them to which contents they are awaiting -
TTTAttributedLabel
A drop-in replacement for UILabel that supports attributes, data detectors, links, and more -
animated-tab-bar
:octocat: RAMAnimatedTabBarController is a Swift UI module library for adding animation to iOS tabbar items and icons. iOS library made by @Ramotion -
MGSwipeTableCell
An easy to use UITableViewCell subclass that allows to display swippable buttons with a variety of transitions. -
JTAppleCalendar
The Unofficial Apple iOS Swift Calendar View. Swift calendar Library. iOS calendar Control. 100% Customizable -
SWTableViewCell
An easy-to-use UITableViewCell subclass that implements a swippable content view which exposes utility buttons (similar to iOS 7 Mail Application) -
FSPagerView
FSPagerView is an elegant Screen Slide Library. It is extremely helpful for making Banner View、Product Show、Welcome/Guide Pages、Screen/ViewController Sliders. -
JVFloatLabeledTextField
UITextField subclass with floating labels - inspired by Matt D. Smith's design: http://dribbble.com/shots/1254439--GIF-Mobile-Form-Interaction?list=users -
XLForm
XLForm is the most flexible and powerful iOS library to create dynamic table-view forms. Fully compatible with Swift & Obj-C. -
SwipeCellKit
Swipeable UITableViewCell/UICollectionViewCell based on the stock Mail.app, implemented in Swift. -
Alerts & Pickers
Advanced usage of UIAlertController and pickers based on it: Telegram, Contacts, Location, PhotoLibrary, Country, Phone Code, Currency, Date... -
SwiftEntryKit
SwiftEntryKit is a presentation library for iOS. It can be used to easily display overlays within your iOS apps. -
TPKeyboardAvoiding
A drop-in universal solution for moving text fields out of the way of the keyboard in iOS -
PageMenu
A paging menu controller built from other view controllers placed inside a scroll view (like Spotify, Windows Phone, Instagram) -
SideMenu
Simple side/slide menu control for iOS, no code necessary! Lots of customization. Add it to your project in 5 minutes or less. -
SWRevealViewController
A UIViewController subclass for presenting side view controllers inspired on the FaceBook and Wunderlist apps, done right ! -
Material Components
[In maintenance mode] Modular and customizable Material Design UI components for iOS -
expanding-collection
:octocat: ExpandingCollection is an animated material design UI card peek/pop controller. iOS library made by @Ramotion
InfluxDB - Purpose built for real-time analytics at any scale.
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of PagerTabStripView or a related project?
README
PagerTabStripView
<!-- -->
Made with :heart: by Xmartlabs team. XLPagerTabStrip for SwiftUI!
Introduction
PagerTabStripView is the first pager view built in pure SwiftUI. It provides a component to create interactive pager views which contains child views. It allows the user to switch between your views either by swiping or tapping a tab bar item.
Unlike Apple's TabView it provides:
- Flexible way to fully customize pager tab views.
- Each pagerTabItem view can be of different type.
- Bar that contains pager tab item is placed on top.
- Indicator view indicates selected child view.
onPageAppear
callback to easily trigger actions when page is selected.- Ability to update pagerTabItem according to highlighted, selected, normal state.
..and we've planned many more functionalities, we have plans to support each one of the XLPagerTabStrip styles.
Usage
Creating a page view is super straightforward, you just need to place your custom tab views into a PagerTabStripView
view and apply the pagerTabItem( _: )
modifier to each one to specify its navigation bar tab item.
import PagerTabStripView
struct MyPagerView: View {
var body: some View {
PagerTabStripView() {
MyFirstView()
.pagerTabItem {
TitleNavBarItem(title: "Tab 1")
}
MySecondView()
.pagerTabItem {
TitleNavBarItem(title: "Tab 2")
}
if User.isLoggedIn {
MyProfileView()
.pagerTabItem {
TitleNavBarItem(title: "Profile")
}
}
}
}
}
To specify the initial selected page you can pass the selection
init parameter.
struct MyPagerView: View {
@State var selection = 1
var body: some View {
PagerTabStripView(selection: $selection) {
MyFirstView()
.pagerTabItem {
TitleNavBarItem(title: "Tab 1")
}
...
..
.
}
}
}
As you may've already noticed, everything is SwiftUI code, so you can update the child views according to SwiftUI state objects as shown above with if User.isLoggedIn
.
Customize pager style
PagerTabStripView provides 5 different ways to show the views. You can select it and customize some aspects of each one using the pagerTabStripViewStyle
modifier.
Scrollable style
In this style you can add as many pages as you want. The tabs are placed in a scroll. The customizable settings are:
- Spacing between navigation bar items
- Navigation bar height
- Indicator bar height
- Indicator bar color
struct PagerView: View {
var body: some View {
PagerTabStripView(selection: 1) {
MyView()
.pagerTabItem {
TitleNavBarItem(title: "First big width")
}
AnotherView()
.pagerTabItem {
TitleNavBarItem(title: "Short")
}
...
..
.
}
.pagerTabStripViewStyle(.scrollableBarButton(indicatorBarColor: .blue, tabItemSpacing: 15, tabItemHeight: 50))
}
}
In this example, we add some settings like the tab bar height, indicator bar color and tab item spaces. Let's watch how it looks!
Button bar style
In this style, the width of the tabs is equal between the different tabs and doesn't adapt to its content size. The customizable settings are:
- Spacing between navigation bar items
- Navigation bar height
- Indicator bar height
- Indicator bar color
struct PagerView: View {
var body: some View {
PagerTabStripView(selection: 1) {
MyView()
.pagerTabItem {
TitleNavBarItem(title: "Tab 1")
}
AnotherView()
.pagerTabItem {
TitleNavBarItem(title: "Tab 2")
}
if User.isLoggedIn {
ProfileView()
.pagerTabItem {
TitleNavBarItem(title: "Profile")
}
}
}
.pagerTabStripViewStyle(.barButton(indicatorBarColor: .gray, tabItemSpacing: 0, tabItemHeight: 50))
}
}
In this example, we add some settings like the tab bar height, indicator bar color and indicator bar height. Let's watch how it looks!
Bar style
This style only shows a bar that indicates the current view controller. The customizable settings are:
- Spacing between navigation bar items
- Indicator bar height
- Indicator bar color
Segmented style
This style uses a Segmented Picker to indicate which view is being displayed. You can indicate the selected color, its padding and if you want it to be set in the toolbar.
Custom style
This style uses the provided view to indicate and background Views to create the item bar. You can use any and fully customized Views for the indicator and the background view in any way you need.
.pagerTabStripViewStyle(
.custom(
tabItemHeight: 48,
indicator: {
Text("👍🏻")
.offset(x: 0, y: -24)
},
background: {
LinearGradient(
colors: 🌈,
startPoint: .topLeading,
endPoint: .bottomTrailing
)
.opacity(0.2)
}
)
)
See how it looks:
Navigation bar
The navigation bar supports custom tab items. You need to specify its appearance creating a struct that implements View
protocol.
For simplicity, we are going to implement a nav bar item with only a title. You can find more examples in the example app.
struct TitleNavBarItem: View {
let title: String
var body: some View {
VStack {
Text(title)
.foregroundColor(Color.gray)
.font(.subheadline)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.white)
}
}
Customize selected and highlighted items
You can define the style of your nav items when they are selected or highlighted by conforming PagerTabViewDelegate
protocol in your nav item view.
In the following example we change the text and background color when the tab is highlighted and selected.
private class NavTabViewTheme: ObservableObject {
@Published var textColor = Color.gray
@Published var backgroundColor = Color.white
}
struct TitleNavBarItem: View, PagerTabViewDelegate {
let title: String
@ObservedObject fileprivate var theme = NavItemTheme()
var body: some View {
VStack {
Text(title)
.foregroundColor(theme.textColor)
.font(.subheadline)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(theme.backgroundColor)
}
func setState(state: PagerTabViewState) {
switch state {
case .selected:
self.theme.textColor = .blue
self.theme.backgroundColor = .lightGray
case .highlighted:
self.theme.textColor = .pink
default:
self.theme.textColor = .gray
self.theme.backgroundColor = .white
}
}
}
onPageAppear modifier
onPageAppear
callback allows you to trigger some action when a page view gets selected, either by scrolling to it or tapping its tab. This modifier is applied only to its associated page view.
struct PagerView: View {
var body: some View {
PagerTabStripView(selection: 1) {
MyView(model: myViewModel)
.pagerTabItem {
TitleNavBarItem(title: "Tab 1")
}
.onPageAppear {
model.reload()
}
}
.pagerTabStripViewStyle(.barButton(indicatorBarHeight: 2, indicatorBarColor: .gray, tabItemSpacing: 0, tabItemHeight: 50))
}
}
Examples
Follow these 3 steps to run Example project
- Clone PagerTabStripView repo.
- Open PagerTabStripView workspace.
- Run the Example project.
Installation
CocoaPods
To install PagerTabStripView using CocoaPods, simply add the following line to your Podfile:
pod 'PagerTabStripView', '~> 2.0'
Carthage
To install PagerTabStripView using Carthage, simply add the following line to your Cartfile:
github "xmartlabs/PagerTabStripView" ~> 2.0
Requirements
- iOS 14+
- Xcode 13.X
Author
Getting involved
- If you want to contribute please feel free to submit pull requests.
- If you have a feature request please open an issue.
- If you found a bug or need help please check older issues and threads on StackOverflow (Tag 'PagerTabStripView') before submitting an issue.
Before contribute check the CONTRIBUTING file for more info.
If you use PagerTabStripView in your app We would love to hear about it! Drop us a line on Twitter.
*Note that all licence references and agreements mentioned in the PagerTabStripView README section above
are relevant to that project's source code only.