How to remove the line separators from a List in SwiftUI without using ForEach?

前端 未结 13 1749
盖世英雄少女心
盖世英雄少女心 2021-01-30 04:50

I have this code to display a list of custom rows.

struct ContentView : View {
    var body: some View {
        VStack(alignment: .leading) {
            List(1         


        
13条回答
  •  清酒与你
    2021-01-30 05:27

    iOS 14:

    you may consider using a LazyVStack inside a ScrollView instead.


    iOS 13:

    There is a UITableView behind SwiftUI's List for iOS 13. So to remove

    Extra separators (below the list):

    you need a tableFooterView and to remove

    All separators (including the actual ones):

    you need separatorStyle to be .none

    init() {
        if #available(iOS 14.0, *) { 
            // iOS 14 doesn't have extra separators below the list by default.
        } else {
            // To remove only extra separators below the list:
            UITableView.appearance().tableFooterView = UIView()
        }
    
        // To remove all separators including the actual ones:
        UITableView.appearance().separatorStyle = .none
    }
    
    var body: some View {
        List {
            Text("Item 1")
            Text("Item 2")
            Text("Item 3")
        }
    }
    

    Note that a static list doesn't show extra separators below the list by default

提交回复
热议问题