tatasec.org
  • Home
  • Privacy Policy
  • Contact Us
  • Guest Post – Write For Us
  • Sitemap
tatasec.org

Elegant Pager View fully written in pure SwiftUI

  • James Gussie
  • September 9, 2021
Total
0
Shares
0
0
0

Tired of getting the same old email notifications? Let’s build a better email app. Today we’ll build an elegant and functional pager view and modularize the code so we can reuse it in other projects.

When Apple launched the iPhone 4, I was immediately drawn to its new design. It was the first iPhone to truly look like an iPhone, not some cheap, plastic imitation. I was impressed by its industrial design, and I had to have the phone. I was also immediately drawn to its new feature, the pager view. The pager view took previously unseen design cues from the industrial design of Apple’s laptops, and was ultimately the highlight of the iPhone 4.

If you’re looking for a new way to view and interact with your application’s data, then you might be interested in using a pager. It’s a great way of displaying large amounts of data that would otherwise clutter the screen of your application. In this article, I’ll show you how to create a pager for a simple application.

The Xmartlabs team created this. Introducing the XLPagerTabStrip for SwiftUI!

Introduction

PagerTabStripView is the first pure SwiftUI pager view. It comes with a component for creating interactive pager views with child views. Swiping or touching a tab bar item enables the user to move between your views.

Unlike Apple’s TabView, it has the following features:

  1. Pager tab displays may be completely customized in a variety of ways.
  2. Different types of pagerTabItem views are possible.
  3. On top of the pager tab item is a bar with the pager tab item.
  4. The indicator view shows the child view that has been chosen.
  5. When a page is chosen, use the onPageAppear callback to quickly initiate actions.
  6. Ability to update pagerTabItem based on whether it is highlighted, chosen, or normal.

We have plans to support each of the XLPagerTabStrip designs, and we have many more features planned.

Usage

To make a page view, just put your custom tab views in a PagerTabStripView view and use the pagerTabItem( _: ) modifier to define the navigation bar tab item for each one.

PagerTabStripView struct MyPagerView: View var body: some View PagerTabStripView() MyFirstView() import PagerTabStripView struct MyPagerView: View var body: some View PagerTabStripView() MyFirstView() MySecondView() pagerTabItem TitleNavBarItem(title: “Tab 1”) pagerTabItem if User.isLoggedIn MyProfileView(), pagerTabItem TitleNavBarItem(title: “Tab 2”) pagerTabItem TitleNavBarItem(title: “Tab 2”) pagerTabItem TitleNavBarItem(title: “Tab 2”) pagerTabItem TitleNavBarItem(title pagerTabItem TitleNavBarItem(title: “Profile”) navBarItem(title: “Profile”) navBarItem(title: “Profile”) navBarItem(title: “Profile”) navBarItem(title: “Profile”) nav

Elegant-Pager-View-fully-written-in-pure-SwiftUI

The selection init option may be used to define the first chosen page.

@State var selection = 1 var body: some struct MyPagerView: View MyFirstView() is a PagerTabStripView(selection: $selection) view. pagerTabItem TitleNavBarItem(title: “Tab 1”)………………………

Everything is SwiftUI code, as you may have seen, thus you can change the child views based on SwiftUI state objects, as demonstrated above with if User.isLoggedIn.

Customize the pager’s appearance.

PagerTabstripView has three alternative methods of displaying the views. Using the pagerTabStripViewStyle modification, you may pick it and modify certain features of each one.

Typical fashion

This is most certainly the most popular pager configuration. The following options may be changed:

  • The distance between the elements in the navigation bar
  • Height of the navigation bar
  • Height of the indicator bar
  • Color of the indicator bar

var body: some struct PagerView: View View PagerTabStripView (PagerTabStripView) (PagerTabStripView (selection: 1) MyView() is a function that returns a view. TitleNavBarItem(title: “Tab 1”) pagerTabItem AnotherView() is a function that returns another view. titleNavBarItem(title: “Tab 2”) pagerTabItem ProfileView().pagerTabItem TitleNavBarItem(title: “Profile”) if User.isLoggedIn pagerTabStripViewStyle(.normal(indicatorBarColor:.gray, tabItemSpacing: 0, tabItemHeight: 50)) pagerTabStripViewStyle(.normal(indicatorBarColor:.gray, tabItemSpacing: 0, tabItemHeight: 50)) pagerTabStripViewStyle(.normal(indicatorBar

In this example, we set the height of the tab bar, the color of the indicator bar, and the height of the indicator bar. Let’s see how it turns out!

1630715982_899_Elegant-Pager-View-fully-written-in-pure-SwiftUI

Bar style

This design simply displays a bar that shows which view controller is currently active. The following options may be changed:

  • The distance between the elements in the navigation bar
  • Height of the indicator bar
  • Color of the indicator bar

1630715983_554_Elegant-Pager-View-fully-written-in-pure-SwiftUI

segmented design

A Segmented Picker is used in this design to identify which view is being shown. You may specify the chosen color, padding, and whether or not it should be shown in the toolbar.

1630715984_374_Elegant-Pager-View-fully-written-in-pure-SwiftUI

Bar of navigation

Custom tab items may be added to the navigation bar. You must create a struct that implements the View protocol to define its appearance.

We’ll use a nav bar item with just a title for simplicity’s sake. More examples may be found in the sample app.

View struct TitleNavBarItem: struct TitleNavBarItem: struct TitleNavBarItem: struct TitleNavBarItem: struct body: some string var body: some string var body: some string var body Text(title).foregroundColor(Color.gray).font(.subheadline) View VStack .background(Color.white).frame(maxWidth:.infinity, maxHeight:.infinity)

Customize the things you’ve chosen and highlighted.

By adhering to the PagerTabViewDelegate protocol in your nav item view, you may specify the style of your nav items when they are chosen or highlighted.

When the tab is highlighted and chosen, we alter the text and background color in the following example.

@Published var textColor = Color.gray @Published var backgroundColor = Color.white private class NavTabViewTheme: ObservableObject @Published var textColor = Color.gray @Published var backgroundColor = Color.white let title: String @ObservedObject fileprivate var theme = NavItemTheme struct TitleNavBarItem: View, PagerTabViewDelegate () body variable: some View VStack is an acronym for Virtual Stack. .foregroundColor(theme.textColor).font(.subheadline) Text(title).foregroundColor(theme.textColor) .background(theme.backgroundColor).frame(maxWidth:.infinity, maxHeight:.infinity) switch state case.selected: self.theme.textColor =.blue self.theme.backgroundColor =.blue func setState(state: PagerTabViewState) func setState(state: PagerTabViewState) func setState(state: PagerTabViewState) func setState(state: PagerTabViewState) func setState .light color self.theme.textColor =.pink; self.theme.textColor =.pink; self.theme.textColor =.pink; self.theme.textColor self.theme.textColor =.gray self.theme.backgroundColor =.white self.theme.textColor =.gray

1630715985_39_Elegant-Pager-View-fully-written-in-pure-SwiftUI

Modifier onPageAppear

When a page view is chosen, either by scrolling to it or clicking its tab, the onPageAppear callback enables you to do some action. This modification is only applied to the page view with which it is connected.

var body: some struct PagerView: View View PagerTabStripView (PagerTabStripView) (PagerTabStripView (selection: 1) MyView(model: myViewModel) is a class that represents a view. TitleNavBarItem(title: “Tab 1”) pagerTabItem model.reload() if onPageAppear is true. pagerTabStripViewStyle(.normal(indicatorBarHeight: 2, indicatorBarColor:.gray, tabItemSpacing: 0, tabItemHeight: 50)) pagerTabStripViewStyle(.normal(indicatorBarHeight: 2, indicatorBarColor:.gray, tabItemSpacing: 0, tabItemHeight: 50)) pagerTabStripViewStyle(.normal(indic

Examples

To run the Example project, follow these three steps.

  • PagerTabStripView is a clone of the PagerTabStripView repo.
  • Open the workspace PagerTabStripView.
  • Use the Example project to get started.

Installation

CocoaPods

Simply add the following line to your Podfile to install PagerTabStripView using CocoaPods:

2.0′ “> pod ‘PagerTabStripView’, ‘~> 2.0’

Carthage

To use Carthage to install PagerTabStripView, just add the following line to your Cartfile:

2.0 “> github “xmartlabs/PagerTabStripView” ~> 2.0

Requirements

Author

Participating in the process

  • Please feel free to send pull requests if you wish to help.
  • Please file an issue if you have a feature request.
  • Please review previous problems and discussions on StackOverflow (Tag ‘PagerTabStripView’) before filing an issue if you discovered a bug or need assistance.

Check the CONTRIBUTING file for additional information before contributing.

We’d love to hear about how you used PagerTabStripView in your app! Send us a message on Twitter.

GitHub

https://github.com/xmartlabs/PagerTabStripView

Related Tag

  • swiftui swipe between views
Total
0
Shares
Share 0
Tweet 0
Pin it 0
James Gussie

Previous Article

Skyrim on PlayStation VR: Tips and Tricks

  • James Gussie
  • September 8, 2021
View Post
Next Article

Nasty bug causes Windows 10 Start menu to pop up on Windows 11

  • James Gussie
  • September 9, 2021
View Post
Table of Contents
  1. Introduction
  2. Usage
    1. Customize the pager’s appearance.
  3. Bar of navigation
    1. Modifier onPageAppear
  4. Examples
  5. Installation
    1. CocoaPods
    2. Carthage
  6. Requirements
  7. Author
  8. Participating in the process
  9. GitHub
Featured
  • facebook alphabet microsoft usbursztynskycnbc 1
    Facebook Marketplace: The Ultimate Guide
    • June 7, 2022
  • 2
    Whatsapp New Icon
    • April 14, 2022
  • 3
    Fix: PS4 Controller Won’t Turn On Or Charge on Playstation
    • December 22, 2021
  • 4
    Xfinity WiFi Hotspots For PC Free Download – Windows 10, 8, 7 and Mac
    • December 22, 2021
  • 5
    Best Microphone Stand- Ultimate Guide 2022
    • December 21, 2021
Must Read
  • 1
    Download greenbrier church evans ga for PC Windows 10,8,7
  • 2
    Download, Install & play Grim Quest Old School RPG NAME on PC (Windows & Mac)
  • 3
    5 Best Laptops for Telehealth 2021
tatasec.org
  • Home
  • Privacy Policy
  • Contact Us
  • Guest Post – Write For Us
  • Sitemap
Stay Updated Always.

Input your search keywords and press Enter.