从TableView中的单元格中删除突出显示的文本

时间:2020-12-13 10:44:13

从TableView中的单元格中删除突出显示的文本

Depending on the status of each pin in the map, each cell in the TableView displays a different color. For changing each color I've not used UIColor.someColor() method, in fact I've used:

根据映射中每个引脚的状态,TableView中的每个单元格显示不同的颜色。为了改变每种颜色,我没有使用过UIColor.someColor()方法,实际上我用过:

UIColor(red: 28/255, green: 198/255, blue: 25/255, alpha: 0.4) //Light red

I would like to remove that highlighted color that is appearing inside each cell. Don't k now if this is a code issue or is something that is inside the TableView/Cell atributes.

我想删除每个单元格中出现的突出显示的颜色。如果这是一个代码问题,或者是TableView / Cell属性中的内容,请不要现在。

I am setting the colors inside the ViewController:

我在ViewController中设置颜色:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cellIdentifier = "Cell"

    var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? UITableViewCell
    if cell == nil {

        cell = UITableViewCell(style: UITableViewCellStyle.Value2, reuseIdentifier: cellIdentifier)
    }


    cell!.textLabel!.text = myFeed.objectAtIndex(indexPath.row).objectForKey("NOMBRE") as? String

    var aux: String = "BLIBRES"
    var aux2: String = "ALIBRES"
    var estado: String = "ESTADO"

    cell!.detailTextLabel!.text = "Anclajes Libres: \(myFeed.objectAtIndex(indexPath.row).objectForKey(aux2)!) | Bicicletas Libres: \(myFeed.objectAtIndex(indexPath.row).objectForKey(aux)!)"

    if myFeed.objectAtIndex(indexPath.row).objectForKey(estado)! as! String == "NO COMUNICA" {

        cell?.backgroundColor = UIColor(red: 28/255, green: 198/255, blue: 25/255, alpha: 0.4)
    } else if myFeed.objectAtIndex(indexPath.row).objectForKey(estado)! as! String == "COMUNICA" {

        cell?.backgroundColor = UIColor(red: 218/255, green: 71/355, blue: 71/255, alpha: 0.4)
    } else if myFeed.objectAtIndex(indexPath.row).objectForKey(estado)! as! String == "ALARMAS" {

        cell?.backgroundColor = UIColor(red: 248/255, green: 155/255, blue: 18/255, alpha: 0.4)
    }

    return cell!
}

1 个解决方案

#1


0  

Solved!

解决了!

I did not know that apart from setting a background color to the cell itself, you can set a background color to the text (and also detailText) of the cell. Inside the func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { } method add the following:

我不知道除了为单元格本身设置背景颜色外,您还可以为单元格的文本(以及detailText)设置背景颜色。在func tableView(tableView:UITableView,cellForRowAtIndexPath indexPath:NSIndexPath) - > UITableViewCell {}方法内添加以下内容:

cell?.textLabel?.backgroundColor = UIColor.clearColor()
cell?.detailTextLabel?.backgroundColor = UIColor.clearColor()

And then the text is displayed correctly without the borders that looked like a highlighted text when setting a custom background color to a cell.

然后,在为单元格设置自定义背景颜色时,文本显示正确,没有看起来像突出显示文本的边框。

从TableView中的单元格中删除突出显示的文本

#1


0  

Solved!

解决了!

I did not know that apart from setting a background color to the cell itself, you can set a background color to the text (and also detailText) of the cell. Inside the func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { } method add the following:

我不知道除了为单元格本身设置背景颜色外,您还可以为单元格的文本(以及detailText)设置背景颜色。在func tableView(tableView:UITableView,cellForRowAtIndexPath indexPath:NSIndexPath) - > UITableViewCell {}方法内添加以下内容:

cell?.textLabel?.backgroundColor = UIColor.clearColor()
cell?.detailTextLabel?.backgroundColor = UIColor.clearColor()

And then the text is displayed correctly without the borders that looked like a highlighted text when setting a custom background color to a cell.

然后,在为单元格设置自定义背景颜色时,文本显示正确,没有看起来像突出显示文本的边框。

从TableView中的单元格中删除突出显示的文本