Reputation: 469
I have this simple list that displays custom views. I can't figure out how to change the colour of the background of the cells.
List(weeksTasks, id: \.self){ week in
let index = weeksTasks.firstIndex(of: week)
WeekPlanRowView(hours: weekHours![index ?? 0], title: week, complete: false)
.padding(.bottom, 15)
}
I would like to change the white to green, any suggestions?
I have tried this:
init(weekNum: Int, weeksTasks: [String], weekDescription: String, hoursPerWeek: Int){
UITableView.appearance().backgroundColor = UIColor(red: 0.96, green: 0.96, blue: 0.96, alpha: 0)
UITableViewCell.appearance().backgroundColor = UIColor(red: 0.96, green: 0.96, blue: 0.96, alpha: 0)
UITableView.appearance().tableFooterView = UIView()
}
and .listRowBackground(Color.green)
Upvotes: 1
Views: 756
Reputation: 257749
Try the following - use ForEach inside List and apply
List {
ForEach(weeksTasks, id: \.self){ week in
let index = weeksTasks.firstIndex(of: week)
WeekPlanRowView(hours: weekHours![index ?? 0], title: week, complete: false)
.padding(.bottom, 15)
}
.listRowBackground(Color.green) // << here !!
}
Tested with Xcode 12.4 / iOS 14.4
Upvotes: 2