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/ScrollViewSectionKitREADME
ScrollViewSectionKit
A SwiftUI library that allows you to add native (plain, grouped, insetGrouped) or custom section styles within the ScrollView SwiftUI component.
Overview
- 💎 Made with 100% SwiftUI.
- 🚀 Lightweight, no external dependencies.
- ✅ The API tries to mimic Apple's
Listcomponent but you can use it within theScrollViewcomponent. - 🎨 The predefined
.plain,.groupedand.insetGroupedsection 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
node-connect
346.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
346.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
346.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
