NEW: Learn to build amazing SwiftUI apps for macOS with my new book! >>

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.


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.


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.


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.


Hacking with Swift is sponsored by RevenueCat

SPONSORED Spend less time managing in-app purchase infrastructure so you can focus on building your app. RevenueCat gives everything you need to easily implement, manage, and analyze in-app purchases and subscriptions without managing servers or writing backend code.

Get Started

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

Reply to this topic…

You need to create an account or log in to reply.

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.