[英]Swift Change label text color on tap from within TableViewCell
[英]How to change text color of label in tableViewCell in Swift?
我在tableViewCell中有一个标签为“ lblProjeDurumu”。 我从soap webServices到此标签获取数据。 数据为“ Devam Ediyor”或“Başlamadı”。 我想如果传入数据是“ Devam Ediyor”,则lblProjeDurumu的textColor为绿色,如果传入数据是“Başlamadı”,则lblProjeDurumu的textColor为红色。 我的代码在这里。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "projelerCell", for: indexPath) as! ProjelerCell
cell.contentView.backgroundColor = UIColor(white: 0.95, alpha: 1)
// Fill the projeler cell
cell.lblProjeAdi.text = ( projeler.object(at: indexPath.row) as AnyObject ).value(forKey: "Proje_Adi") as? String
cell.lblProjeDurumu.text = ( projeler.object(at: indexPath.row) as AnyObject ).value(forKey: "Durumu") as? String
cell.lblTarih.text = ( projeler.object(at: indexPath.row) as AnyObject ).value(forKey: "Kayit_Tarihi") as? String
if ( cell.lblProjeDurumu.text == "Başlamadı"){
cell.lblProjeDurumu.textColor = UIColor.red
}
else if ( cell.lblProjeDurumu.text == "Devam Ediyor"){
cell.lblProjeDurumu.textColor = UIColor.green
}
return cell
}
但是没有变化。 lblProjeDurumu的textColor仍然是默认颜色。 如何根据传入数据更改tableViewCell中Label的textColor。
只有在您输入的任何条件下,您的颜色才会更改。 您是否检查过其中任何条件是否确实在执行?
if ( cell.lblProjeDurumu.text == "Başlamadı"){
cell.lblProjeDurumu.textColor = UIColor.red
}
else if ( cell.lblProjeDurumu.text == "Devam Ediyor"){
cell.lblProjeDurumu.textColor = UIColor.green
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.