Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove List Separator lines in SwiftUI 2.0 in iOS 14

So the question is pretty simple and it's in the title. I want to remove the line separator in SwiftUI iOS 14. Previously, I was using UITableView().appearance().separatorStyle = .none and that used to do the job in iOS 13. Now however, it doesn't work. Any update or idea on how to make it work. Thanks:)

like image 234
Osama Naeem Avatar asked Jun 26 '20 14:06

Osama Naeem


People also ask

How do I delete a separator line in SwiftUI?

Unfortunately, there is no official way to remove line separators in SwiftUI. That said, we can make use of the UIKit API to tweak the line separator of the List view in SwiftUI.

How do I change the divider color in SwiftUI?

Changing SwiftUI Divider Colors You can change its color by overlay it with the color you want using . overlay() modifier. Text("A visual element that can be used to separate other content.") Use overlay modifier to change the color of a divider.

How do I create a list in SwiftUI?

Probably the simplest way to build a list is to create a new SwiftUI view and wrap the Hello World text in a List: struct StaticListView: View { var body: some View { List { Text("Hello, world!") } } } To add more items to the list, we can just add another line: List { Text("Hello, world!") Text("Hello, SwiftUI!") }


1 Answers

Here is a demo of possible solution. Tested with Xcode 12b.

demo

List {     ForEach(0..<3) { _ in         VStack {             Text("Hello, World!").padding(.leading)         }         .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)         .listRowInsets(EdgeInsets())         .background(Color.white)     } } 
like image 147
Asperi Avatar answered Sep 19 '22 03:09

Asperi