I want the height of the UILabel to expand depending on its text.
Here's what the view controller looks like, with the label selected:

Here is the code (I tried a bunch of different similar things, but this is what I have now):
import UIKit class ViewControllerTEST: UIViewController { @IBOutlet weak var label: UILabel! override func viewDidLoad() { super.viewDidLoad() label.frame = CGRectMake(0, 0, CGRectGetWidth(label.bounds), 0) label.numberOfLines = 0 label.lineBreakMode = .ByWordWrapping label.text = "This is a really\nlong string" label.setNeedsLayout() label.sizeToFit() label.frame = CGRectMake(0, 0, CGRectGetWidth(label.bounds), CGRectGetHeight(label.bounds)) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning()
And, as you can see here, this does not work as intended:

source share