title: Auto resize the UIView based on UILabel's content through Auto Layout
body: <p>I have a requirement on showing a banner view to show a message,</p>
  
  <p>Now the message's content may vary and the view should also resize depending on <code>UILabel</code>s content. </p>
  
  <p><code>UILabel</code> is set to <code>Word Wrap</code> and <code>numberOfLines</code> is set to <code>0</code></p>
  
  <p>The design in <code>xib</code> is,
  <a href="https://i.stack.imgur.com/5Q29w.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5Q29w.png" alt="Auto layout"></a><a href="https://i.stack.imgur.com/gPlyV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gPlyV.png" alt="Auto Layout 2"></a></p>
  
  <p>And the respective class file is,</p>
  
  <pre><code>import UIKit
  
  class ORABannerView: UIView {
  
      @IBOutlet weak var bannerText: UILabel!
  
      static func instantiate(message: String) -&gt; ORABannerView {
          let view: ORABannerView = initFromNib() ?? ORABannerView()
          view.bannerText.text = message
          return view
      }
  
      override init(frame: CGRect) {
          super.init(frame: frame)
      }
  
      required init?(coder aDecoder: NSCoder) {
          super.init(coder: aDecoder)
      }
  
      override func draw(_ rect: CGRect) {
          super.draw(rect)
      }
  }
  </code></pre>
  
  <p>The <code>initFromNib</code> is an implemented as UIView's extension,</p>
  
  <pre><code>extension UIView {
      class func initFromNib&lt;T: UIView&gt;() -&gt; T? {
          guard let view = Bundle.main.loadNibNamed(String(describing: self), owner: nil, options: nil)?[0] as? T else {
              return nil
          }
          return view
      }
  }
  </code></pre>
  
  <p>Tried with <code>layoutIfNeeded()</code> on the view, but it's not working for me.</p>
  
  <p>Any suggestions will be appreciated.</p>