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

时间:2015-08-24 11:55:08

标签: swift uitableview

View

根据地图中每个图钉的状态,TableView中的每个单元格都会显示不同的颜色。为了更改每种颜色,我没有使用UIColor.someColor()方法,事实上我已经使用了:

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

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

我在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 个答案:

答案 0 :(得分:0)

解决!

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

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

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

Solved unwanted highlighted text problem!