How to make a Horizontal List in SwiftUI? How to make a Horizontal List in SwiftUI? ios ios

How to make a Horizontal List in SwiftUI?


You need to add .horizontal property to the scrollview. otherwise it won't scroll.

ScrollView (.horizontal, showsIndicators: false) {     HStack {         //contents     }}.frame(height: 100)


Starting from iOS 14 beta1 & XCode 12 beta1 you will be able to wrap LazyHStack in a ScrollView to create a horizontal lazy list of items, i.e., each item will only be loaded on demand:

ScrollView(.horizontal) {            LazyHStack {                ForEach(0...50, id: \.self) { index in                    Text(String(index))                        .onAppear {                            print(index)                        }                }            }        }


To make a horizontal scrollable content, you can wrap a HStack inside a ScrollView:

ScrollView {  HStack {    ForEach(0..<10) { i in      Text("Item \(i)")      Divider()    }  }}.frame(height: 40)