如何使用swift 3更改表格单元格内的标签颜色? [英] How to change label color inside table cell with swift 3?

查看:32
本文介绍了如何使用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

我在 MediaPackListCell.swift 文件中声明了这个 @IBOutlet weak var lblAllowAutoRenew: UILabel!.

TableView.swift 中,

I declare this @IBOutlet weak var lblAllowAutoRenew: UILabel! in MediaPackListCell.swift file.

In 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

}


每个单元格都有详细的披露.
没有任何效果.... :(
这种情况对我来说太奇怪了.我将标签拖到 UI 中并选择标签,然后更改颜色.但是,它不起作用.
有人可以帮我吗?


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. But, it does not work.
Could anyone help me please?

推荐答案

尝试替换下面的行

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

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

并确保您使用了正确的重用标识符planCell",您已将其用于 Tablecell.swift

And make sure you are using right reuse identifier "planCell" , which you have used for Tablecell.swift

这篇关于如何使用swift 3更改表格单元格内的标签颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆