SwiftUI Disable Scroll in ScrollView or List
Reading time: 1 min
This recipe shows how to disable scrolling in a ScrollView or List, while still allowing interactions with its subviews. The end result looks like this:
The trick is to use a DragGesture
with minimumDistance
of zero, which will then intercept scrolling touches, while still allowing taps an...
SwiftUI Multiple Buttons in List Row
Reading time: 1 min
This quick recipe shows how to enable multiple Buttons in a List row. This is a long standing SwiftUI bug/quirk that fortunately has an easy workaround. Say you've put a few buttons in a List
row:
using code like this:
List {
HStack {
Button("First button") {
print("First actio...
Sticky List Header in SwiftUI
Reading time: 1 min
This recipe shows how to add a sticky header to a List in SwiftUI. It also allows for a scrolling part of the header, as well as multiple sticky headers. The end result looks like this:
The recipe goes as follows:
- Use
Section(header:)
to define the sticky header and the content beneath...
SwiftUI List Section Index Title
Reading time: 3 min
This recipe shows how to add section index with titles to a SwiftUI List. This will render a vertical list of custom shortcuts on the right-hand side of the list, allowing you to quickly navigate to any section by pressing or just moving your finger over it. The same functionality in UITableVie...
SwiftUI Timeline list
Reading time: 2 min
This recipe shows how to implement a timeline list in SwiftUI. Timeline list has a line, usually on the side, that connects rows / cells tied to the same date. The end result looks like this:
The example list in this recipe deals with a simple structure that represents an appointment, defi...