gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 14:07:29 25 4
gpt4 key购买 nike

View

根据 map 中每个图钉的状态,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!
}

最佳答案

解决了!

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

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

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

Solved unwanted highlighted text problem!

关于swift - 从 TableView 中的单元格中删除突出显示的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32181707/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com