swiftuiswiftui-list

Is there a way to hide scroll indicators in a SwiftUI List?


I want to create a SwiftUI List, but not show scroll indicators. ScrollView offers showsIndicators to do this. How can it be done?


Solution

  • iOS 16

    There is a simple view modifier for this now:

    List {
       ,,,
    }
    .scrollIndicators(.hidden) // šŸ‘ˆ Apply this modifier on the list or any other scrollable content
    

    Any Indicators (List, scrollView, etc.) - Works from iOS 13

    you can get rid of showing indicators for all Lists, but with an API of the UITableView. because SwiftUI List is using UITableView for iOS behind the scene:

    struct ContentView: View {
        
        init() {
            UITableView.appearance().showsVerticalScrollIndicator = false
        }
        
        var body: some View {
            List(0...100, id: \.self) { item  in
                Text("hey")
            }
        }
    }
    

    Note that this will eliminate all TableViews and Lists indicators. You should make it visible again if you need to.


    āš ļø Not Yet Important Note

    Seems like Apple is removing appearance hacks (but not for this one yet). So you can use LazyVStack inside and ScrollView instead of List and use the available argument for hiding the indicators.

    struct ContentView: View {
        var body: some View {
            ScrollView(.vertical, showsIndicators: false) { // <- This argument
                LazyVStack {
                    ForEach(1...100, id: \.self) {
                        Text("\($0)").frame(height: 40)
                    }
                }
            }
        }
    }