Swift 更改以前记录的UITableView中的颜色单元格
如何更改已添加单元格的颜色 如果单元格更改了将添加到UITableView的颜色,则我需要更改所有TableView中单元格的颜色Swift 更改以前记录的UITableView中的颜色单元格,swift,uitableview,cell,uicolor,Swift,Uitableview,Cell,Uicolor,如何更改已添加单元格的颜色 如果单元格更改了将添加到UITableView的颜色,则我需要更改所有TableView中单元格的颜色 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cell_1") as! Tabl
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell_1") as! TableView_Cell
let item = self.items[indexPath.row]
cell.la_view.text = item.list_1
cell.la_view2.text = item.list_2
switch sw {
case 0:
cell.la_view.textColor = UIColor.green
cell.la_view2.textColor = UIColor.green
case 1:
cell.la_view.textColor = UIColor.white
cell.la_view2.textColor = UIColor.white
default:
print("")
}
cell.backgroundColor = UIColor(named: "Defeult")
return cell
}
如果只有两种颜色,则可以使用布尔变量:
var colorSwitch = false
然后在tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableView单元格{
:
if colorSwitch {
cell.la_view.textColor = //color
cell.la_view2.textColor = //color
else {
cell.la_view.textColor = //color
cell.la_view2.textColor = //color
如果要更改的颜色不止一种,则可以使用整数值并使用已有的switch case语句。如果只有两种颜色,则可以使用布尔变量:
var colorSwitch = false
然后在tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableView单元格{
:
if colorSwitch {
cell.la_view.textColor = //color
cell.la_view2.textColor = //color
else {
cell.la_view.textColor = //color
cell.la_view2.textColor = //color
如果要更改多个颜色,可以使用整数值并使用已有的switch case语句。如果要更改所有单元格,只需切换布尔值并调用
tableView.reloadData()
将刷新tableView。如果希望更改所有单元格,只需切换布尔值并调用tableView.reloadData()
将刷新tableView。