Skip to content

Native Segmented Control + Page View implementation for SwiftUI. Supports iOS/iPadOS 13+ and visionOS 1+

License

Notifications You must be signed in to change notification settings

samdawes/SegmentedControlPageView

Repository files navigation

SegmentedControlPageView

Offers a seamless integration of a segmented control and a page view in native SwiftUI applications. Users can navigate between pages by swiping or tapping on segments in the control. Compatible with iOS 13+ and visionOS 1+. 2024-02-18 18 34 46 2024-02-18 18 54 14

Usage

The following example shows a possible onboarding process. The segmented control has three segments with the labels Welcome, Features, and Next Steps that correspond to three custom SwiftUI views: WelcomeView(), FeaturesView(), and NextStepsView().

import SegmentedControlPageView

@State var currentSelection: Int = 0

SegmentedControlPageView(
  "Onboarding Process",
  selection: $currentSelection,
  labels: [
    "Welcome",
    "Features",
    "Next Steps"
  ],
  pages: [
    WelcomeView(),
    FeaturesView(),
    NextStepsView()
  ]
)

If you'd like to use the page view without the segmented control, initialize a PageView in your project. This will fall back to a UIKit implementation for older versions of iOS, to ensure consistency on all versions.

PageView([
  WelcomeView(),
  FeaturesView(),
  NextStepsView()
], selection: $currentSelection)

Requirements

  • iOS 13.0 or later
  • visionOS 1.0 or later

Installation

Swift Package Manager

In Xcode go to Project -> Your Project Name -> Package Dependencies -> Tap Plus. Insert url:

https://github.com/samdawes/SegmentedControlPageView

or add it to the dependencies section in your Package.swift file:

dependencies: [
    .package(url: "https://github.com/samdawes/SegmentedControlPageView", .upToNextMajor(from: "1.0.0"))
]

Manually

If you prefer not to use Swift Package Manager, you can integrate manually. Put the Sources/SegmentedControlPageView folder in your Xcode project. Make sure to enable Copy items if needed and Create groups.

Apps Using

If your app uses SegmentedControlPageView, don't hesitate to add yours to the list!