How to make List reversed in SwiftUI

后端 未结 2 471
栀梦
栀梦 2021-02-06 15:52

I\'m new in SwiftUI, trying to make something like reverse in Android LinearLayoutManager

mess         


        
2条回答
  •  被撕碎了的回忆
    2021-02-06 16:16

    There is a trick on UITableView that you flip the table and each cell. So it appears to be filling from bottom. You can do this trick in SwiftUI too:

    Fully Working Demo:

    struct ContentView: View {
        @State private var ids = [String]()
    
        init() {
            UITableView.appearance().tableFooterView = UIView()
            UITableView.appearance().separatorStyle = .none
        }
    
        var body: some View {
            ZStack {
                List(ids, id: \.self) { id in
                    Text(id).scaleEffect(x: 1, y: -1, anchor: .center)
                }.scaleEffect(x: 1, y: -1, anchor: .center)
    
                Button("Touch") {
                    self.ids.append(UUID().uuidString)
                }
            }
        }
    }
    

提交回复
热议问题