SwiftUI stack views with paged scrolling behaviour.
Warning
This package is no longer maintained. Use ScrollView and scrollTargetBehaviour instead.
A view that arranges its children in a horizontal line, and provides paged scrolling behaviour.
HPageView(alignment: .leading, pageWidth: 250, spacing: 12) {
//Pages
}
alignment
: The guide for aligning the pages in this page view.pageWidth
: The width of each page, ornil
if you want each page to fill the width of the page view.spacing
: The distance between adjacent pages, ornil
if you want the page view to choose a default distance for each pair of pages.content
: A view builder that creates the content of this page view.
A view that arranges its children in a vertical line, and provides paged scrolling behaviour.
VPageView(alignment: .top, pageHeight: 250, spacing: 12) {
//Pages
}
alignment
: The guide for aligning the pages in this page view.pageHeight
: The height of each page, ornil
if you want each page to fill the height of the page view.spacing
: The distance between adjacent pages, ornil
if you want the page view to choose a default distance for each pair of pages.content
: A view builder that creates the content of this page view.
A view that arranges its children in a line, and provides paged scrolling behaviour.
Changes to the layout axis will cause the pages to lose any internal state, and will not be animated.
PageView(.horizontal, alignment: .leading, pageLength: 250, spacing: 12) {
//Pages
}
axis
: The layout axis of this page view.alignment
: The guide for aligning the pages in this page view.pageLength
: The length of each page, parallel to the layout axis, ornil
if you want each page to fill the length of the page view.spacing
: The distance between adjacent pages, ornil
if you want the page view to choose a default distance for each pair of pages.content
: A view builder that creates the content of this page view.
A view that provides programmatic paging, by working with a proxy to move to child pages.
PageViewReader { proxy in
HPageView {
//Pages
Button("First") {
withAnimation {
proxy.moveToFirst()
}
}
}
}
content
: The reader's content, containing a page view.
A proxy value that supports programmatic paging of the first page view within a view hierarchy.
moveTo(index:)
: Scans the first page view contained by the proxy for the page with the index closest toindex
, and then moves to that page.moveToFirst()
: Scans the first page view contained by the proxy for the first page, and then moves to that page.moveToLast()
: Scans the first page view contained by the proxy for the last page, and then moves to that page.
The strictPageAlignment
view modifier can be used to control whether page views always use their provided alignment to position pages. Without this modifier pages will be aligned to prevent leaving empty space in the page view.
- Changes to the layout axis of a
PageView
will cause the pages to lose any internal state, and will not be animated. - Active paging animations in a page view may interfere with other animations when the number of pages changes.
- Nested page views are not currently supported.
- iOS 14.0+ or watchOS 7.0+
- Xcode 12.0+
- Install with Swift Package Manager.
- Import
SwiftUIPageView
to start using.
@ciaranrobrien on Twitter.