article

Monday, September 6, 2021

SwiftUI Horizontal List - Horizontal Scroll View

SwiftUI Horizontal List - Horizontal Scroll View

In this tutorial i'm going to show how to implement horizontal list in SwiftUI.

ContentView.swift
 
//
//  ContentView.swift
//  swiftuidev
//
//  Created by Cairocoders
//

import SwiftUI

struct ContentView: View {
    
    var body: some View {
        
        ScrollView(.horizontal, showsIndicators : false) {
            HStack {
                ForEach(0..<5) { i in
                    cardView(img: "photo\(i)")
                }
            }
        }
    }
}

struct cardView : View {
    var img = ""
    
    var body: some View {
        VStack {
            Image(img)
                .resizable()
                
        }
        .frame(width: 250, height: 400)
        .cornerRadius(20)
    }
}
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Related Post