繁体   English   中英

更改UITableView中的颜色单元格先前记录的Swift

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM