How can I change the colour of separator in list of SwiftUI?
Try this
var body: some View {
UITableView.appearance().separatorColor = UIColor.blue
return List(){
ForEach(users, id: \.self) { user in
HStack{
Image("helmet").resizable().frame(width: 40, height: 40, alignment: .leading)
VStack(alignment : .leading){
Text(user).font(.custom("SFProText-Semibold", size: 14))
Text("Blu Connect").font(.custom("SFProText-Semibold.ttf", size: 11))
}
}
}
.onDelete(perform: delete)
}
}
This is a kind of global variable, so you are changing the separator colour in all UITableViews from your app (List and Form are using UITableViews under the hood)
How to remove List Separator lines in SwiftUI 2.0 in iOS 14 and above
Here is a demo of possible solution. Tested with Xcode 12b.
List {
ForEach(0..<3) { _ in
VStack {
Text("Hello, World!").padding(.leading)
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
.listRowInsets(EdgeInsets())
.background(Color(UIColor.systemBackground)))
}
}
How to color/remove the separator between last and second to last row in a SwiftUI List?
You can use ScrollView
with ForEach
instead of default List
. It will be without default styling, and you can define your own style.
struct ContentView: View {
@State private var words = (1...50).map{ String($0) }
var body: some View {
GeometryReader { geometry in
ScrollView {
ForEach(self.words, id: \.self) { word in
Text(word)
}
.frame(width: geometry.size.width)
}
}
}
}
How do I modify the background color of a List in SwiftUI?
Ok, I found the solution for coloring the list rows:
struct TestRow: View {
var body: some View {
Text("This is a row!")
.listRowBackground(Color.green)
}
}
and then in body:
List {
TestRow()
TestRow()
TestRow()
}
This works as I expect, but I have yet to find out how to then remove the dividing lines between the rows...
Modify the background colour of a List in SwiftUI?
Removing ContentView1
's init
fixes the problem.
The issue is caused by your code setting selectedBackgroundView
, but you don't need any of that init
anyway as it still functions as you intend.
Related Topics
How to Add a Show More/Show Less Uibutton to Control Uitextview
Hmac Sha512 Using Commoncrypto in Swift 3.1
How to Conform an Observableobject to the Codable Protocols
Background Upload with Share Extension
Swift- How to Display Image Over Button
How to Retrieve All Available Finder Tags
How to Implement a 'Next' Property to a Caseiterable Enum in Swift
Can Somebody Post a Good Example of MVC Pattern in Swift
How to Correctly Do Up an Adjustable Split View in Swiftui
Saving Coredata to a Web Server with Swift 3.0
How to Perform Face Detection in Swift
How to Select All Text in a Uitextfield Using Swift
How to Make Function That Some Parameters Not Required in When Call It in iOS Swift 3
Ios15 Uttype Deprecations for Url-Extension