UILabel sizeToFit with relative font size not working
<p>If I have a multiline string which I put in a UILabel, 
set the font size relative to the bounds of the view, 
and then I call <code>sizeToFit</code>,
all of which happens in <code>drawRect:</code>,
it perfectly sizes my label. 
Once <code>drawRect:</code> is called again because of an orientation change,
it screws up the size needed to fit.</p>

<p><code>self.bounds.width</code> is much bigger than the label needs in all cases.</p>

<p>code:</p>

<pre><code>import UIKit

class CustomView: UIView {
    var label = UILabel()

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.contentMode = .Redraw
        addSubview(label)
    }

    override func drawRect(rect: CGRect) {
        let string = "this is line 1\r\nand\r\nthis is line 3"
        label.numberOfLines = 3
        label.text = string
        label.font = label.font.fontWithSize(self.bounds.width / 30)
        label.lineBreakMode = NSLineBreakMode.ByWordWrapping
        label.textAlignment = NSTextAlignment.Center

        label.sizeToFit()

        label.backgroundColor = UIColor.grayColor()
        label.textColor = UIColor.whiteColor()

        label.center = self.center
    }
}
</code></pre>

<p>initially everything looks OK:</p>

<p><a href="https://i.stack.imgur.com/5cpZA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5cpZA.png" alt="enter image description here"></a></p>

<p>But when my bounds change because of a different orientation:</p>

<p><a href="https://i.stack.imgur.com/tbjLu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tbjLu.png" alt="enter image description here"></a></p>

<p>Any ideas what am I doing wrong here? By the way, it's the width that somehow doesn't want to grow. because if I set <code>label.numberOfLines = 0</code>, it does grow, but only in height.</p>