简体   繁体   English

如何使用Swift 3更改表格单元格内的标签颜色?

[英]How to change label color inside table cell with swift 3?

I put label inside table cell. 我将标签放在表格单元格中。 I changed the text color into "White" in Attributes inspector. 我在“属性”检查器中将文本颜色更改为“白色”。 I also changed the label background color into "Green". 我还将标签背景色更改为“绿色”。
When I run the app, the text color does not change into white color but background changed to green. 当我运行该应用程序时,文本颜色不会变为白色,而背景变为绿色。 I also put the code. 我也把代码。

 cell.lblName.textColor = UIColor.white

I declare this @IBOutlet weak var lblAllowAutoRenew: UILabel! 我声明此@IBOutlet弱var lblAllowAutoRenew:UILabel! in MediaPackListCell.swift file. MediaPackListCell.swift文件中。

In TableView.swift , TableView.swift中

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

 let cell = tableView.dequeueReusableCell(withIdentifier: "planCell",for: indexPath) as! MediaPackListCell

 cell.lblAllowAutoRenew.textColor = UIColor.white

}


Each cell has detail disclosure. 每个单元都有详细信息。
Nothing is working .... :( 什么都没用.... :(
This case is so strange for me. 这种情况对我来说很奇怪。 I dragged the label into UI and select the label and then change the color. 我将标签拖到UI中,然后选择标签,然后更改颜色。 But, it does not work. 但是,它不起作用。
Could anyone help me please? 有人可以帮我吗?

Try replacing line below 尝试替换下面的行

 let cell = tableView.dequeueReusableCell(withIdentifier: "planCell",for: indexPath) as! MediaPackListCell

with

 let cell = tableView.dequeueReusableCell(withIdentifier: "planCell",for: indexPath) as! Tablecell

And make sure you are using right reuse identifier "planCell" , which you have used for Tablecell.swift 并确保您使用的是正确的重用标识符“ planCell”,该标识符已用于Tablecell.swift

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM