PageView is a custom SwiftUI page view that works on all major Apple platforms.
PageView
is a custom SwiftUI page view that works on all major Apple platforms. It mimics a paged TabView and can be set up with a list of pages, a list of items, or a PageViewState
value.
PageView can be installed with the Swift Package Manager:
https://github.com/danielsaidi/PageView.git
You can become a sponsor to help me dedicate more time on my various open-source tools. Every contribution, no matter the size, makes a real difference in keeping these tools free and actively developed.
You can create a PageView
with a collection of page views, an array of page items, or a PageViewState
.
struct MyView: View {
@State var state = PageViewState(pages: Array(0...5))
var body: some View {
PageView(state) { page in
VStack(spacing: 20) {
Text("Page \(page)")
Button(buttonTitle, action: nextPageOrRestart)
.padding(50)
.buttonStyle(.borderedProminent)
}
}
.pageViewAnimation(.bouncy)
.pageViewIndicatorDisplayMode(.automatic)
.pageViewIndicatorStyle(.init(
dotColor: .blue,
currentDotColor: .yellow
))
.background(
color(for: state.pageIndex)
.ignoresSafeArea()
.animation(.easeOut, value: state.pageIndex)
)
}
func color(for index: Int) -> Color {
switch index {
case 0: .red
case 1: .green
case 2: .blue
case 3: .orange
case 4: .pink
case 5: .mint
default: .purple
}
}
func nextPageOrRestart() {
if state.isLastPage {
state.pageIndex = 0
} else {
state.showNextPage()
}
}
}
You can customize the page view animation with the pageViewAnimation(_:)
view modifier, the page indicator display mode with pageViewIndicatorDisplayMode(_:)
and its style with pageViewIndicatorStyle(_:)
.
The online documentation has more information, articles, code examples, etc.
The Demo
folder has an app that lets you test the library.
Feel free to reach out if you have questions or if you want to contribute in any way:
- Website: danielsaidi.com
- E-mail: [email protected]
- Bluesky: @[email protected]
- Mastodon: @[email protected]
PageView is available under the MIT license. See the LICENSE file for more info.