Member-only story

Create an Inset Grouped List in SwiftUI for macOS

Luca Jonscher
2 min readAug 7, 2020

--

When you have an iOS app, especially when it displays information, you maybe use InsetGroupedListStyle on your List . This looks any like this:

iPad, Info from mactracker.ca

But there is a problem, when you want to display this view on macOS. InsetGroupedListStyle is unavailable for native apps (It’s available for Mac Catalyst though). And when you use alternative list styles for the list, it looks like this:

Mac

It doesn’t look that bad, but it is not consistent with the iOS app design.

Creating the view extension

There isn’t a way to create a custom ListStyle . So we create a view extension , that we can use on the sections.

So that we have different code for iOS and macOS, we can use an #if closure. The header parameter has a view as input, and is placed above the header. For the iOS section, we can just use a regular section:

self represents the view you’re using the method on. You can replace the // iOS with this bit of code. But macOS isn’t much more complicated at all. GroupBox fulfills nearly all of our expectations.

--

--

Luca Jonscher
Luca Jonscher

Written by Luca Jonscher

Designer, Developer, Creative. Freelance graphic designer. From Germany. Thrice Apple Swift Student Challenge winner.

No responses yet