iOS Swift How to change or update UILabel attribute in custom UITableViewCell
<p>I want to update/change a UILabel attribute (background color,background shape,etc...) dynamically when I get data from a Web service. </p>

<p>I want to dispaly this Label in difference type by different Lable text, update UILabel attribute according the testdata which got from web server. like that : if get testdata=[1,1,1,1] the UIlabel background color is red , testdata=[2,2,2,2] UILabel background color is blue.etc</p>

<p>I am doing the following:</p>

<p><strong>In Main.Stroyboard:</strong></p>

<p>I add TableView and TableViewCell (choice custom) associated <code>UITableViewCell</code> named <code>TVcell</code> and add a UILabel component.</p>

<p><strong>In TVcell</strong></p>

<pre><code>import UIKit
class TVCell: UITableViewCell {

    @IBOutlet weak var testLabel: UILabel!

    var testdata:TestDataInfo?{
        didSet{
            updateUI()
        }
    }

    private func updateUI(){
        if let mFildata=testdata{
            setStautesLabel()
        }
    }

    private func setStautesLabel(){
        self.testLabel=UILabel(frame: CGRect(x: 50, y: 50, width: 100, height: 35))
        self.testLabel.text = "thisTestLabel"

        self.testLabel.transform = CGAffineTransformMakeRotation(0.2)
        self.superview?.addSubview(self.testLabel)
    }
}
</code></pre>

<p><strong>Methode 1: In TableViewController</strong></p>

<pre><code>func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
    let data = TestDataInfo![indexPath.row]
    let cell = self.TV.dequeueReusableCellWithIdentifier(Storyboard.ProjectAppliedCellIndentifier,forIndexPath: indexPath)
    if let filesDataCell = cell as? TVCell{
        filesDataCell.testdata=data
    }
    return cell
}
</code></pre>

<p><strong>Result 1</strong></p>

<p>Just One Cell testLabel has been change and rest Cell no display testLabel </p>

<p><strong>Methode 2: In TableViewController</strong></p>

<pre><code>func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
    let data = TestDataInfo![indexPath.row]
    let cell = self.TV.dequeueReusableCellWithIdentifier(Storyboard.ProjectAppliedCellIndentifier,forIndexPath: indexPath)
    if let filesDataCell = cell as? TVCell{
        filesDataCell.testdata=data
        // update testLable In there
        let testLable:UILabel=UILabel(frame: CGRect(x: 50, y: 50, width: 100, height: 35))
        testLable.text = "thisLabel"
        testLable.transform = CGAffineTransformMakeRotation(0.2)
        cell.contentView.addSubview(testLable)
    }
    return cell
}
</code></pre>

<p><strong>Result 2</strong></p>

<p>can display TestUILabel in all cell. but not update testLabel original just add new UILabel</p>

<p>but why ? I want to update all UILable in TVCell. Can anyone Help me?</p>