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

Is it possible to make a list with sections that scroll like normal rows?

Forums > SwiftUI

I mean not floating sections.

Apparently you can do that to tableviews by using this code

let dummyViewHeight = CGFloat(40)
self.tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: self.tableView.bounds.size.width, height: dummyViewHeight))
self.tableView.contentInset = UIEdgeInsets(top: -dummyViewHeight, left: 0, bottom: 0, right: 0)

Any ideas for SwiftUI?

Thanks in advance.

1      

By scroll like normal do you mean that they are basically rows with different backrounds and fonts etc? You could fairly easily roll your own on that.

1      

Yes but that would be a hack, and no so beautiful. I mean, I would like them to continue to be sections but to be fixed in place, like titles for the rows of their sections, without floating and hanging at the top.

1      

Whats hacky about it? Section is defined as

public struct Section<Parent, Content, Footer> {

which means you have to supply the internal content youself and SwiftUI will make sure the section floats, or be collapsable. So you provide your own UI either way.

1      

Hacking with Swift is sponsored by Emerge

SPONSORED Why are Swift reference types bad for app startup time, and what’s the performance cost of protocol conformances? That’s just a couple of the topics you can learn about on the Emerge blog — written by the app performance experts behind Emerge’s advanced app optimization and monitoring tools, based on their experience of working at companies like Apple, Airbnb, Snap, and Spotify.

Find out more

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.