I created a list in SwiftUI. I want to change the color or remove the separator as, In UIKit, we can easily change the color of separator in TableView.
Below is the code and UI(image) of the list in SwiftUI
@State private var users = ["Paul", "Taylor", "Adele"]
var body: some View {
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)
}
}
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With