iteraciona/scrollingcarousel
A customizable and interactive horizontal carousel for SwiftUI, designed to display a series of views with smooth scrolling, scaling effects, and optional indicators.
Features
- Supports dynamic scaling of items during scrolling.
- View alignment behavior for smooth transitions.
- Customizable item spacing, scaling, and indicators.
- Uses
scrollPositionto track the current visible item. - Indicator bar that scrolls along with content.
Compatibility
- iOS 17+
- SwiftUI-based
Swift Package Manager (SPM)
- Open your Xcode project.
- Go to
File > Add Packages. - Enter the repository URL:
`` https://github.com/Iteraciona/ScrollingCarousel.git ``
- Choose the latest version and click Add Package.
Usage
import SwiftUI
import ScrollingCarousel
struct ContentView: View {
let items = [
Color.red.frame(width: 200, height: 300),
Color.blue.frame(width: 200, height: 300),
Color.green.frame(width: 200, height: 300)
]
var body: some View {
ScrollingCarousel(content: items) { index in
print("Current index: \(index)")
}
}
}Parameters
| Parameter | Type | Description | |------------------|----------------|-------------| | content | [Content] | An array of SwiftUI views to display in the carousel. | | gap | CGFloat | Space between items. Default: 20. | | normalState | CGFloat | Scale factor for the selected item. Default: 1. | | reducedState | CGFloat | Scale factor for unselected items. Default: 0.85. | | showIndicators | Bool | Whether to show the indicator bar. Default: true. | | indicatorSize | CGFloat | Size of indicator dots. Default: 8. | | indicatorColor | Color | Color of the indicators. Default: .gray. | | indicatorGap | CGFloat | Space between indicators. Default: 4. | | currentIndex | (Int) -> Void | Closure that receives the current index on scroll. |
Customization
You can customize the appearance and behavior by adjusting the parameters.
ScrollingCarousel(
content: items,
gap: 15,
normalState: 1,
reducedState: 0.8,
showIndicators: true,
indicatorSize: 10,
indicatorColor: .blue,
indicatorGap: 6
) { index in
print("Viewing item at index: \(index)")
}License
This project is licensed under the MIT License. See the LICENSE file for details.
Package Metadata
Repository: iteraciona/scrollingcarousel
Default branch: main
README: README.md