title: UIView not resizing from xib file Swift
body: <p>I have created an xib file with a UIView inside of it. I am using this view inside of my storyboard, and would like it to resize based on the content within it. When I explicitly set the height of the view in the storyboard, it is the same height as the XIB file. Each phone screen seems to have the same xib height and width as well, which causes the view to go off the screen, no matter what I set the constraints to be within the storyboard.</p>
  
  <p>I have tried this to hide the view and set the height of the banner to 35</p>
  
  <pre><code>self.specialistBanner.pillView.isHidden = true  
  specialistBannerHeight.constant = 35
  </code></pre>
  
  <p>I have tried </p>
  
  <pre><code>specialistBannerHeight.constant = 35
  </code></pre>
  
  <p>to get the view to be smaller within the storyboard</p>
  
  <p>I have also tried </p>
  
  <pre><code>self.specialistBanner.sizeToFit()
  </code></pre>
  
  <p>with no avail</p>
  
  <p><strong>XIB File for the specialist banner view</strong>
  <a href="https://i.stack.imgur.com/49yOY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/49yOY.png" alt="XIB File for the specialist banner view"></a></p>
  
  <p><strong>Label inside the xib file</strong>
  <a href="https://i.stack.imgur.com/2RwYC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2RwYC.png" alt="Label inside the xib file"></a></p>
  
  <p><strong>Pill View within the xib</strong>
  <a href="https://i.stack.imgur.com/2e0XN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2e0XN.png" alt="Pill View within the xib"></a></p>
  
  <p><strong>Storyboard file using the xib view inside of a view controller</strong>
  <a href="https://i.stack.imgur.com/ppd7V.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ppd7V.png" alt="Storyboard file using the xib view inside of a view controller"></a></p>
  
  <pre><code>class SpecialistBannerView: UIView {
  
  @IBOutlet weak var bannerTitle: UILabel!
  @IBOutlet weak var pillView: PillCollectionView!
  
  var viewModel = SpecialistBannerViewModel()
  
  // Initialize xib
  let SpecialistBannerView = "SpecialistBannerView"
  
  override func awakeFromNib() {
      super.awakeFromNib()
      self.translatesAutoresizingMaskIntoConstraints = false
  }
  
  override init(frame: CGRect) {
      super.init(frame: frame)
      initXib(view: self)
  }
  
  required init?(coder aDecoder: NSCoder) {
      super.init(coder: aDecoder)
      initXib(view: self)
  }
  
  func initXib(view: SpecialistBannerView) {
  
      let viewToShow = Bundle.main.loadNibNamed(SpecialistBannerView, owner: self, options: nil)?[0] as? UIView ?? UIView()
      view.translatesAutoresizingMaskIntoConstraints = false
      view.sizeToFit()
      view.addSubview(viewToShow)
      view.frame = view.bounds
      view.pillView.setUp()
      view.sizeToFit()
  
      view.autoresizingMask = [.flexibleHeight, .flexibleWidth]
  
      viewModel.specialistBannerViewProtocol = self
  }
  </code></pre>
  
  <p>Any help would be appreciated</p>