Component

Scrollable Cards

Learn to add Scrollable Cards to your iOS App (Supports Xcode 16 and iOS 18)

Scrollable Cards

Steps to Create Scrollable Cards:

1. Set Up the Scrollable Card Layout:

  • We’ll use a ScrollView with a horizontal axis and a set of custom cards that users can swipe through.
import SwiftUI

struct ScrollableCardsView: View {
    let items = [
        CardItem(title: "SwiftUI Essentials", image: "swift"),
        CardItem(title: "Mastering Combine", image: "combine"),
        CardItem(title: "iOS Animations", image: "animation"),
        CardItem(title: "Networking with URLSession", image: "network")
    ]

    var body: some View {
        VStack(alignment: .leading) {
            Text("Trending Courses")
                .font(.largeTitle)
                .fontWeight(.bold)
                .padding(.leading)

            ScrollView(.horizontal, showsIndicators: false) {
                HStack(spacing: 20) {
                    ForEach(items) { item in
                        CardView(item: item)
                            .frame(width: 300, height: 200)
                            .shadow(radius: 5)
                    }
                }
                .padding()
            }
        }
    }
}

struct CardView: View {
    let item: CardItem

    var body: some View {
        ZStack {
            Image(item.image)
                .resizable()
                .aspectRatio(contentMode: .fill)
                .frame(width: 300, height: 200)
                .clipped()

            VStack {
                Spacer()
                Text(item.title)
                    .font(.headline)
                    .padding()
                    .frame(maxWidth: .infinity)
                    .background(Color.black.opacity(0.7))
                    .foregroundColor(.white)
            }
        }
        .cornerRadius(15)
    }
}

struct CardItem: Identifiable {
    var id = UUID()
    var title: String
    var image: String
}

struct ContentView: View {
    var body: some View {
        ScrollableCardsView()
    }
}

Time to build your iOS App?

ShipiOS provides you SwiftUI boilerplate, How-to Guides, Components Library and extra rewards!

Get ShipiOS Package
ShipiOS.App

I told you it's more than just a boilerplate :)

Made with ❤️ on 🌍

Need help? Reach out on:

© Copyright 2024 ShipiOS.App - All rights reserved.