Carousel

public struct Carousel<Content> : View where Content : View

Carousel A container view that arranges its child views horizontally, one after the other, with a protion of the next child view visible in the container. It allows users to swipe or scroll through the child views to view fiffeernt piece of content.

Example Initialization and Configuration

Carousel(numberOfColumns: 3, spacing: 8, alignment: .top, isSnapping: true) {
    ForEach(0..<16, id: \.self) { i in
        Text("Text \(i)")
            .font(.title)
            .padding()
            .frame(height: 100)
            .background(Color.gray)
    }
}
.padding(8)
.border(Color.gray)
  • Create a Carousel View

    Declaration

    Swift

    public init(numberOfColumns: Int = 1, spacing: CGFloat = 8, alignment: VerticalAlignment = .top, isSnapping: Bool = true, @ViewBuilder content: @escaping () -> Content)

    Parameters

    numberOfColumns

    Number of columns. The default is 1.

    spacing

    Horizontal spacing between views. The default is 8.

    alignment

    Vertical alignment in the carousel. The default is .top.

    isSnapping

    Whether it stops at a right position that the first visible subview can be displayed fully after scrolling. The default is true.

    content

    The views representing the content of the Carousel

  • Declaration

    Swift

    public var body: some View { get }