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鈥檚 build a horizontally scrolling stack of cards that showcases different content!

1. Set Up the Scrollable Card Layout:

  • We鈥檒l 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

China鈥檚 Zeekr unveils first family SUV, taking on Tesla 路 TechNode
China鈥檚 Zeekr unveils first family SUV, taking on Tesla 路 TechNode
Computing
These are the best gadgets for your pet right now |  News
These are the best gadgets for your pet right now | News
News
miHoYo founder Cai Haoyu sparks debate with prediction on AIGC 路 TechNode
miHoYo founder Cai Haoyu sparks debate with prediction on AIGC 路 TechNode
Computing
OpenAI and Apple secure initial batch of TSMC’s advanced A16 (1.6nm) process capacity 路 TechNode
OpenAI and Apple secure initial batch of TSMC’s advanced A16 (1.6nm) process capacity 路 TechNode
Computing

You Might also Like

China鈥檚 Zeekr unveils first family SUV, taking on Tesla 路 TechNode
Computing

China鈥檚 Zeekr unveils first family SUV, taking on Tesla 路 TechNode

1 Min Read
These are the best gadgets for your pet right now |  News
News

These are the best gadgets for your pet right now | News

5 Min Read
miHoYo founder Cai Haoyu sparks debate with prediction on AIGC 路 TechNode
Computing

miHoYo founder Cai Haoyu sparks debate with prediction on AIGC 路 TechNode

4 Min Read
OpenAI and Apple secure initial batch of TSMC’s advanced A16 (1.6nm) process capacity 路 TechNode
Computing

OpenAI and Apple secure initial batch of TSMC’s advanced A16 (1.6nm) process capacity 路 TechNode

1 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?