# SwiftyCarousel
SwiftyCarousel is a Swift library for creating a customizable carousel component in SwiftUI. It provides an easy way to display a collection of items in a carousel format with various customization options.
## Features
- Display a carousel of items
- Customizable card width, height, and spacing
- Zoom in/out effect for inactive cards
- Adjust carousel spacing with inactive card width
- Set card corner radius
- Show/hide paging indicator with customizable colors and size
- Supports any SwiftUI Views as items
- Requires a minimum version of iOS 15
## Installation
You can install SwiftyCarousel using Swift Package Manager.
```swift
dependencies: [
.package(url: "https://github.com/razvanrujoiu/SwiftyCarousel.git", from: "1.0.0")
]
import SwiftyCarousel
struct ContentView: View {
let items: [AnyView] // Make sure items conform to View
let cardWidth: CGFloat
let cardHeight: CGFloat
let spacing: CGFloat
let inactiveCardHeight: CGFloat
let inactiveCardWidth: CGFloat
let cardCornerRadius: CGFloat
let showPagingIndicator: Bool
let pagingIndicatorActiveColor: Color
let pagingIndicatorInactiveColor: Color
let pagingIndicatorSize: CGFloat
var body: some View {
SwiftyCarousel(
items: items,
cardWidth: cardWidth,
cardHeight: cardHeight,
spacing: spacing,
inactiveCardHeight: inactiveCardHeight,
inactiveCardWidth: inactiveCardWidth,
cardCornerRadius: cardCornerRadius,
showPagingIndicator: showPagingIndicator,
pagingIndicatorActiveColor: pagingIndicatorActiveColor,
pagingIndicatorInactiveColor: pagingIndicatorInactiveColor,
pagingIndicatorSize: pagingIndicatorSize
)
}
}
let sampleItems: [AnyView] = [
AnyView(Color.teal),
AnyView(Color.red),
AnyView(Color.blue)
]
struct ContentView: View {
var body: some View {
SwiftyCarousel(
items: sampleItems,
cardWidth: 300,
cardHeight: 200,
spacing: 16,
inactiveCardHeight: 180,
inactiveCardWidth: 30,
cardCornerRadius: 12,
showPagingIndicator: true,
pagingIndicatorActiveColor: .blue,
pagingIndicatorInactiveColor: .gray,
pagingIndicatorSize: 8
).environmentObject(CarouselState())
}
}
The above example will result in
An array of SwiftUI Views that will be displayed in the carousel. Ensure that each item conforms to the View
protocol.
The width of each card in the carousel.
The height of each card in the carousel.
The spacing between the cards.
The height of inactive cards for the zoom in/out effect when swiping between cards.
Adjusts the carousel spacing by specifying the width of inactive cards.
The radius of the cards.
A flag to show/hide the paging indicator.
The color of the active paging indicator dot.
The color of the inactive paging indicator dots.
The size of the paging indicator dots.
SwiftyCarousel is available under the MIT license. See the LICENSE file for more info.