ScrollViewIfNeeded
  • August 6, 2025

A SwiftUI ScrollView that only scrolls if the content doesn’t fit in the View

Installation


Requirements iOS 13+

Swift Package Manager

  1. In Xcode, open your project and navigate to File → Swift Packages → Add Package Dependency.
  2. Paste the repository URL (https://github.com/dkk/ScrollViewIfNeeded) and click Next.
  3. For Rules, select version.
  4. Click Finish.

Add as dependency to another package

.package(url: “https://github.com/dkk/ScrollViewIfNeeded”, .upToNextMajor(from: “1.0.0”))

Manual installation

Copy /Sources/ScrollViewIfNeeded/ScrollViewIfNeeded.swift into your project

Usage


Import the ScrollViewIfNeeded package to your view:

import ScrollViewIfNeeded

use it like you would use ScrollView:

ScrollViewIfNeeded {
/* your content */
}

configure it the same way you would configure ScrollView:

ScrollViewIfNeeded(.horizontal, showsIndicators: false) {
/* your content */
}

or use it as a ViewModifier:

/* your view */
.makeScrollableIfNeeded(.horizontal)

GitHub


View Github

YOU MIGHT ALSO LIKE...
SwiftUI Shapes

Collection of custom shapes Regular Polygons  

SwiftUITrackableScrollView

Swift Package Manager The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated ...

FancyScrollView

FancyScrollView  

SwiftDux

SwiftDux is a state container inspired by Redux and built on top of Combine and SwiftUI. It helps you write ...

Verge.swift

  Using StoreReader or @Reading in SwiftUI In SwiftUI, there are two ways to observe a Store: using the StoreReader view ...