How to Remove List Line-separator in SwiftUI

Updated for iOS14 — Xcode12

Prafulla Singh
Mac O’Clock

--

SeparatorStyle: .none to .singleLine

Table of content:

  • With iOS 13
  • With iOS14
  • Making Version Based Code
  1. With iOS 13

List in SwiftUI is essentially a UITableView of UIKit. So the appearance changes of UITableView affects List also. Simply changing the UITableView appearance can update the List presentation style.

The problem with appearance is that they apply globally. If we want to remove line separator or any other property from all the List views in App

We can simply do following in didFinishLaunchingWithOptions.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UITableView.appearance().separatorStyle = .none
return true
}

But if we want to update for one specific list. We need to do in it onAppear and revert the property back onDisappear like the following. So that it only affects the designated List.

List {
Text("Message 1")
Text("Message 1")
Text("Message 1")
Text("Message 1")
Text("Message 1")
Text("Message 1")…

--

--