By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
World of SoftwareWorld of SoftwareWorld of Software
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Search
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
Reading: Scrollable Cards in iOS 18 – #30DaysOfSwift | HackerNoon
Share
Sign In
Notification Show More
Font ResizerAa
World of SoftwareWorld of Software
Font ResizerAa
  • Software
  • Mobile
  • Computing
  • Gadget
  • Gaming
  • Videos
Search
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Have an existing account? Sign In
Follow US
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
World of Software > Scrollable Cards in iOS 18 – #30DaysOfSwift | HackerNoon

Scrollable Cards in iOS 18 – #30DaysOfSwift | HackerNoon

News Room
Last updated: 2024/10/20 at 11:07 PM
News Room Published 20 October 2024
Share
SHARE

Day 9: Smooth Scroll with Scrollable Cards! 🎴

For the ninth post of the #30DaysOfSwift series, let’s learn Scrollable Cards in SwiftUI. Scrollable cards or stacks are perfect for showcasing content in a visually appealing, swipeable format.

Image descriptionImage description

Let’s build a horizontally scrolling stack of cards that showcases different content!

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()
    }
}

How does it look for you? Let me know!

Happy Coding!

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Twitter Email Print
Share
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article Social Media & Covid-19: How to Communicate During a Crisis
Next Article Can artificial intelligence rescue customer service?
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected

248.1k Like
69.1k Follow
134k Pin
54.3k Follow

Latest News

Zeekr’s privatization will save “several billion yuan” in R&D · TechNode
Zeekr’s privatization will save “several billion yuan” in R&D · TechNode
Computing
5 ChatGPT Tips And Prompts That Can Help Frequent Flyers Save Money – BGR
5 ChatGPT Tips And Prompts That Can Help Frequent Flyers Save Money – BGR
News
I review mini PCs for a living and these 7 early Black Friday deals let you downsize for less
I review mini PCs for a living and these 7 early Black Friday deals let you downsize for less
News
Xiaomi unveils Xuanjie O1, a self-developed phone chip to launch in late May · TechNode
Xiaomi unveils Xuanjie O1, a self-developed phone chip to launch in late May · TechNode
Computing

You Might also Like

Zeekr’s privatization will save “several billion yuan” in R&D · TechNode
Computing

Zeekr’s privatization will save “several billion yuan” in R&D · TechNode

4 Min Read
5 ChatGPT Tips And Prompts That Can Help Frequent Flyers Save Money – BGR
News

5 ChatGPT Tips And Prompts That Can Help Frequent Flyers Save Money – BGR

10 Min Read
I review mini PCs for a living and these 7 early Black Friday deals let you downsize for less
News

I review mini PCs for a living and these 7 early Black Friday deals let you downsize for less

2 Min Read
Xiaomi unveils Xuanjie O1, a self-developed phone chip to launch in late May · TechNode
Computing

Xiaomi unveils Xuanjie O1, a self-developed phone chip to launch in late May · TechNode

3 Min Read
//

World of Software is your one-stop website for the latest tech news and updates, follow us now to get the news that matters to you.

Quick Link

  • Privacy Policy
  • Terms of use
  • Advertise
  • Contact

Topics

  • Computing
  • Software
  • Press Release
  • Trending

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

World of SoftwareWorld of Software
Follow US
Copyright © All Rights Reserved. World of Software.
Welcome Back!

Sign in to your account

Lost your password?