问题
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