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

試著忘記壹切 提交于 2019-12-24 09:38:03

问题


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! 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

}


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?


回答1:


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



来源:https://stackoverflow.com/questions/45117730/how-to-change-label-color-inside-table-cell-with-swift-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!