This example shows how a label’s width can automatically resize when the text content changes.

Pin the left and top edges

Just use auto layout to add constraints to pin the left and top sides of the label.

After that it will automatically resize.

Notes

import UIKit
class ViewController: UIViewController {

    @IBOutlet weak var myLabel: UILabel!

    @IBAction func changeTextButtonTapped(sender: UIButton) {
        myLabel.text = "my name is really long i want it to fit in this box"
    }
}