UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Horizontal Paging ScrollView?

Forums > SwiftUI

Can someone point me in the right direction on how I can load 4 different Views Horizontally.

View1, View2, View3 and View 4

I find allot of examples, except relating to my problem.

Sincerely, Robert

3      

Think you want to do this! ScrollView(.horizontal) with a HStack EG

struct ContentView: View {
    let arrayImage = ["tortoise", "ant", "ladybug", "leaf", "flame", "iphone", "homepod", "applewatch", "macpro.gen3"]

    var body: some View {
        ScrollView(.horizontal, showsIndicators: false) {
            HStack {
                ForEach(arrayImage, id: \.self) { image in
                    Image(systemName: image)
                }
                .font(.largeTitle)
                .padding()
            }
        }

    }
}

replace Image with view that you want to show

3      

SADLY , I can not grasp to make it work. Thank you for just replying.

3      

Wouldn't a TABview be a better choice?

eg (in an app.swift file -- or something similar in the ContentView.swift file)

import SwiftUI @main struct YourApp: App { var body: some Scene { WindowGroup {
TabView { FirstView() SecondView() ThirdView() FourthView() } .tabViewStyle(PageTabViewStyle()) } } }

3      

Hi @hcri50

Think the problem is people do not know what you want to do!

3      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.