此库简化了 SwiftUI 应用程序中轮播图风格界面的实现,同时保持平滑、无限滚动的特性。

CarouselView

特性

♾️ 无限滚动支持

🎯 选定项目跟踪

📏 可配置的项目间距

📍 当前索引监控

⚡️ 原生 SwiftUI 实现

Swift Package Manager (SPM)

CarouselView 可通过 SPM 获取。 使用以下 URL 添加为依赖项

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

用法

import CarouselView

struct ContentView: View {
    private let items: [String] = ["One", "Two", "Three", "Four", "Five"]
    @State private var selectedIndex: Int = 2
    
    var body: some View {
        CarouselView(
            items,
            spacing: 10.0,
            selectedIndex: $selectedIndex
        ) { item in
            Text(item)
                .frame(maxWidth: .infinity)
                .frame(height: 200)
                .background(Color.gray)
                .clipShape(RoundedRectangle(cornerSize: .init(width: 5, height: 5)))
        }
    }
}

作者

Anbalagan D

许可证

CarouselView 在 MIT 许可证下可用。 有关更多信息,请参阅 LICENSE 文件。