tableViewCell에 "lblProjeDurumu"라는 레이블이 있습니다. soap webServices에서이 레이블로 데이터를 가져옵니다. 데이터는 "Devam Ediyor"또는 "Başlamadı"입니다. 들어오는 데이터가 "Devam Ediyor"이고 lblProjeDurumu의 textColor가 녹색이고 들어오는 데이터가 "Başlamadı"이면 lblProjeDurumu의 textColor가 빨간색입니다. 내 코드가 여기 있습니다.Swift에서 tableViewCell의 레이블 텍스트 색상을 변경하는 방법은 무엇입니까?
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'및 'else if'블록에 중단 점을 추가하려고 했습니까? 어쩌면 문자열에 공백이있을 수 있습니다. 이 경우 비교가 실패합니다. – dasdom
답변 해 주셔서 감사합니다. 나는 문제를 해결한다. 당신이 말했듯이, 문자열에 공간이 있습니다. 나는 "Başlamadı"와 "Başlamadı"그리고 "Devam Ediyor"를 "Devam Ediyor"로 변경하여 문제가 해결되었습니다. –