WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

How to hide the scroll indicators in ScrollView, List, and more

Paul Hudson    @twostraws   

Updated for Xcode 14.0 beta 1

New in iOS 16

SwiftUI’s scrollIndicators() modifier allows us to determine whether to show the scroll indicators or not – those are the little flashing bars that both give the user a sense of the size of our content, but also allows for a long press scroll.

Use it like this:

struct ContentView: View {
    var body: some View {
        List(1..<100) { i in
            Text("Row \(i)")
        }
        .scrollIndicators(.hidden)
    }
}

Download this as an Xcode project

There are four options available to us, and there are subtle distinctions:

  1. The default is .automatic, which is what you’d get without the modifier in place - SwiftUI will do whatever it thinks is best.
  2. Specify .visible to get auto-hiding indicators on iOS, or to respect whatever is the user’s preference on macOS.
  3. Use .hidden to hide the indicators on iOS, and mostly hide them on macOS too – if the user connects a mouse, the scroll indicators will return.
  4. Use .never to hide the indicators on iOS and also on macOS, regardless of what pointing device user has.
Hacking with Swift is sponsored by RevenueCat

SPONSORED You know StoreKit, but you don’t want to do StoreKit. RevenueCat makes it easy to deploy, manage, and analyze in-app subscriptions on iOS and Android so you can focus on building your app.

Explore the docs

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

Similar solutions…

BUY OUR BOOKS
Buy Pro Swift Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift (Vapor Edition) Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Server-Side Swift (Kitura Edition) Buy Beyond Code

Was this page useful? Let us know!

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.