[英]Change color cell in UITableView Previously recorded Swift
如何更改已添加的單元格的顏色?
如果更改單元格的顏色(將添加到UITableView的顏色),則需要更改所有TableView中單元格的顏色。
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 indexPath: IndexPath) -> UITableViewCell {
:
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語句。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.