SkillAgentSearch skills...

ScrollViewSectionKit

A SwiftUI library that allows you to add native (plain, grouped, insetGrouped) or custom section styles within the ScrollView SwiftUI component.

Install / Use

/learn @pavolkmet/ScrollViewSectionKit
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

ScrollViewSectionKit

A SwiftUI library that allows you to add native (plain, grouped, insetGrouped) or custom section styles within the ScrollView SwiftUI component.

<img src="Resources/Preview - 1.png" alt="The preview of the `ScrollViewSectionKit` on iPhones 14 Pro Max. The 1st one shows plain style. The 2nd one shows grouped style. The 3rd one shows inset grouped style. The 4th one shows custom style.">

Overview

  • 💎 Made with 100% SwiftUI.
  • 🚀 Lightweight, no external dependencies.
  • ✅ The API tries to mimic Apple's List component but you can use it within the ScrollView component.
  • 🎨 The predefined .plain, .grouped and .insetGrouped section styles, but you can also define a completely custom section style.
  • 🧪 Tested in multiple production applications.
  • 📑 Well documented API.

Requirements

  • iOS 14.0+
  • watchOS 7.0+
  • tvOS 14.0+
  • macOS 11.0+

Installation

Swift Package Manager

The ScrollViewSectionKit is available via the Swift Package Manager.

https://github.com/pavolkmet/ScrollViewSectionKit

CocoaPods

The ScrollViewSectionKit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'ScrollViewSectionKit'

Then just run pod install.

Manually

Just drag and drop all files from folder Source in the ScrollViewSectionKit into your project and select Copy items if needed.

Usage

import ScrollViewSectionKit

struct ContentView: View {
    
    var body: some View {
        ScrollView {
            VStack(spacing: 0.0) {
                ScrollViewSection {
                    Text("This is a 1st row.")
                    Text("This is a 2nd row.")
                } header: {
                    Text("Section header".uppercased())
                } footer: {
                    Text("Section footer")
                }
            }
        }
        .scrollViewSectionStyle(.insetGrouped)
        .scrollViewSectionBackgroundColor(.clear)
        .background {
            Color(uiColor: UIColor.systemGroupedBackground)
                .ignoresSafeArea()
        }
    }
    
}

See example application for all examples and advanced usage.

Configuration

Section - Style

You can customize the appearance of section by applying different styles using the scrollViewSectionStyle(_ style: any ScrollViewSectionStyle) modifier. This modifier can be used globally or per section. The library already contains the .plain, .grouped and .insetGrouped styles.

In the following example the first ScrollViewSection uses the .grouped style because it is set as part of the ScrollView component but the second ScrollViewSection uses .insetGrouped style. This is because under the hood the scrollViewSectionStyle(_ style: any ScrollViewSectionStyle) modifier is using EnvironmentKey. This means that you can use this modifier to set a global style for the entire application.

import ScrollViewSectionKit

struct ContentView: View {
    
    var body: some View {
        ScrollView {
            VStack(spacing: 0.0) {
                ScrollViewSection {
                    Text("This is a 1st row.")
                    Text("This is a 2nd row.")
                } header: {
                    Text("Section header".uppercased())
                } footer: {
                    Text("Section footer")
                }
                ScrollViewSection {
                    Text("This is a 1st row.")
                    Text("This is a 2nd row.")
                } header: {
                    Text("Section header".uppercased())
                } footer: {
                    Text("Section footer")
                }
                .scrollViewSectionStyle(.insetGrouped)
            }
        }
        .scrollViewSectionStyle(.grouped)
        .scrollViewSectionBackgroundColor(.clear)
        .background {
            Color(uiColor: UIColor.systemGroupedBackground)
                .ignoresSafeArea()
        }
    }
    
}

It should look like this ⬇️

<p align="center"> <img src="Resources/Example 1.png" width="320"> </p>

Section - Background Color

You can customize the appearance of section by applying different background colors using the scrollViewSectionBackgroundColor(_ color: Color) modifier. This modifier can be used globally or per section.

In the following example the first ScrollViewSection uses the .blue.opacity(0.28) background color because it is set as part of the ScrollView component but the second ScrollViewSection uses .orange.opacity(0.28) background color. This is because under the hood the scrollViewSectionBackgroundColor(_ color: Color) modifier is using EnvironmentKey. This means that you can use this modifier to set a global style for the entire application.

import ScrollViewSectionKit

struct ContentView: View {
    
    var body: some View {
        ScrollView {
            VStack(spacing: 0.0) {
                ScrollViewSection {
                    Text("This is a 1st row.")
                    Text("This is a 2nd row.")
                } header: {
                    Text("Section header".uppercased())
                } footer: {
                    Text("Section footer")
                }
                ScrollViewSection {
                    Text("This is a 1st row.")
                    Text("This is a 2nd row.")
                } header: {
                    Text("Section header".uppercased())
                } footer: {
                    Text("Section footer")
                }
                .scrollViewSectionStyle(.insetGrouped)
                .scrollViewSectionBackgroundColor(.orange.opacity(0.28))
            }
        }
        .scrollViewSectionStyle(.grouped)
        .scrollViewSectionBackgroundColor(.blue.opacity(0.28))
        .background {
            Color(uiColor: UIColor.systemGroupedBackground)
                .ignoresSafeArea()
        }
    }
    
}

It should look like this ⬇️

<p align="center"> <img src="Resources/Example 2.png" width="320"> </p>

Section - Container Type

You can customize the performance of section by changing its container type using the scrollViewSectionContainerType(_ type: ScrollViewSectionContainerType) modifier. This modifier can be used globally or per section.

In the following example the first ScrollViewSection uses the .VStack container type because it is set as part of the ScrollView component but the second ScrollViewSection uses .LazyVStack container type. This is because under the hood the scrollViewSectionContainerType(_ type: ScrollViewSectionContainerType) modifier is using EnvironmentKey. This means that you can use this modifier to set a global style for the entire application.

import ScrollViewSectionKit

struct ContentView: View {
    
    var body: some View {
        ScrollView {
            VStack(spacing: 0.0) {
                ScrollViewSection {
                    Text("This is a 1st row.")
                    Text("This is a 2nd row.")
                } header: {
                    Text("Section header".uppercased())
                } footer: {
                    Text("Section footer")
                }
                ScrollViewSection {
                    Text("This is a 1st row.")
                    Text("This is a 2nd row.")
                } header: {
                    Text("Section header".uppercased())
                } footer: {
                    Text("Section footer")
                }
                .scrollViewSectionStyle(.insetGrouped)
                .scrollViewSectionBackgroundColor(.orange.opacity(0.28))
                .scrollViewSectionContainerType(.LazyVStack)
            }
        }
        .scrollViewSectionStyle(.grouped)
        .scrollViewSectionBackgroundColor(.blue.opacity(0.28))
        .scrollViewSectionContainerType(.VStack)
        .background {
            Color(uiColor: UIColor.systemGroupedBackground)
                .ignoresSafeArea()
        }
    }
    
}

Row - Background Color

You can customize the appearance of row by applying different background colors using the scrollViewRowBackgroundColor(_ color: Color?) modifier. This modifier can be used per section or per row.

In the following example the second row of the first section uses the .blue.opacity(0.28) background color because it is set as part of row. The first row of the second section, on the other hand, uses .green.opacity(0.28) background color because the entire section uses this modifier and the last row of the second section uses the .orange.opacity(0.28) background color.

import ScrollViewSectionKit

struct ContentView: View {
    
    var body: some View {
        ScrollView {
            VStack(spacing: 0.0) {
                ScrollViewSection {
                    Text("This is a 1st row.")
                    Text("This is a 2nd row.")
                        .scrollViewRowBackgroundColor(.blue.opacity(0.28))
                } header: {
                    Text("Section header".uppercased())
             

Related Skills

View on GitHub
GitHub Stars47
CategoryDevelopment
Updated16d ago
Forks4

Languages

Swift

Security Score

95/100

Audited on Mar 17, 2026

No findings