Is there any way to make a paged ScrollView in SwiftUI?

前端 未结 7 1425
轻奢々
轻奢々 2021-02-03 15:02

I\'ve been looking through the docs with each beta but haven\'t seen a way to make a traditional paged ScrollView. I\'m not familiar with AppKit so I am wondering if this doesn\

7条回答
  •  不要未来只要你来
    2021-02-03 15:11

    Not sure if this helps your question but for the time being while Apple is working on adding a Paging View in SwiftUI I've written a utility library that gives you a SwiftUI feel while using a UIPageViewController under the hood tucked away.

    You can use it like this:

    Pages {
        Text("Page 1")
        Text("Page 2")
        Text("Page 3")
        Text("Page 4")
    }
    

    Or if you have a list of models in your application you can use it like this:

    struct Car {
        var model: String
    }
    
    let cars = [Car(model: "Ford"), Car(model: "Ferrari")]
    
    ModelPages(cars) { index, car in
        Text("The \(index) car is a \(car.model)")
            .padding(50)
            .foregroundColor(.white)
            .background(Color.blue)
            .cornerRadius(10)
    }
    

提交回复
热议问题