๐Ÿ‘”StackForEach

โฌ†๏ธ ้œ€่ฆ๏ผš๐Ÿ“ฆ ScrollHStackForEach, ๐Ÿ“ฆ ScrollVStackForEach

struct ContentView: View {
    var body: some View {
        HStack {
            Group {
                // ๐Ÿ“ฆ ScrollHStackForEach
                ScrollHStackForEach(0..<60) { numberBall($0) }
                // ๐Ÿ“ฆ ScrollVStackForEach
                ScrollVStackForEach(0..<30) { numberBall($0) }
                    .frame(height: 400)
            }
            .border(Color.yellow)      // scroll view border (yellow)
            .padding()
            .background(Color.gray4)
            .border(Color.pink)        // padding border (pink)
            .padding()
        }
    }
}

extension ContentView {
    /// number in a circle
    func numberBall(_ i: Int) -> some View {
        ZStack {
            Circle()
                .fill(Color.purple)
                .frame(width: 60, height: 60)
            Text("\(i)")
        }
        .font(.largeTitle)
        .shadow(radius: 4)
    }
}

Last updated