title: Swift label which gets text from url is changing size when scrolling collectionView
body: <p>In a CollectionView there are multiple Cells. All of them have a genreLabel with text from url. The text is getting displayed, but when I scroll in the CollectionView, some genreLabel are getting smaller, so the text is not completely displayed anymore. The function <code>setupViews()</code> is used to create constraints in CollectionViewCell and properties are set in the function <code>configure()</code>. Also there is a second problem coming with that: when the genreLabel is getting smaller, the <code>discountLabel</code> is disappearing too.</p>
  
  <p>I tried to put the call of <code>setupViews()</code> in different places. When I put it in the init of CollectionViewCell the genreLabel is so small, it only shows one Letter of the text. When I put it at the end of <code>configure()</code> or after <code>cell.configure()</code> in <code>collectionView(cellForItemAt)</code> I get the problem I have right now.</p>
  
  <p>The CollectionViewController:</p>
  
  <pre><code>class HomeController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, HomeControllerDelegate {
  
      lazy var eventCollectionView: UICollectionView = {
          let layout = UICollectionViewFlowLayout()
          layout.minimumInteritemSpacing = 25
          layout.minimumLineSpacing = 25
          let cv = UICollectionView(frame: CGRect(x: 25, y: 108, width: UIScreen.main.bounds.width - 50, height: UIScreen.main.bounds.height - 108), collectionViewLayout: layout)
          cv.dataSource = self
          cv.delegate = self
          return cv
      }()
  
      var homeEvents = [HomeEvent]()
  
      let homeCellId = "HomeCellId"
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          //Setting up the NavigationController...
  
          HomeModel.shared.getEvents {
              (response) in
              self.homeEvents = response.homeEvents
              self.eventCollectionView.reloadData()
          }
          eventCollectionView.register(HomeCell.self, forCellWithReuseIdentifier: homeCellId)
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          imageCache.removeAllObjects()
      }
  
      override var preferredStatusBarStyle: UIStatusBarStyle {
          return .lightContent
      }
  
      func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
          return homeEvents.count
      }
  
      func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
          guard let cell = eventCollectionView.dequeueReusableCell(withReuseIdentifier: homeCellId, for: indexPath) as? HomeCell
              else {
                  return UICollectionViewCell()
          }
          let event = homeEvents[indexPath.item]
          cell.configure(with: event)
  //        cell.setupViews()
          cell.homeControllerDelegate = self
          return cell
      }
  
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -&gt; CGSize {
          if view.frame.width &lt; 415.0 {
              return CGSize(width: view.frame.width - 50, height: view.frame.width - 60)
          }
          else if view.frame.width &lt; 828.0 {
              return CGSize(width: (view.frame.width / 2) - 50, height: (view.frame.width / 2) - 60)
          }
          else {
              return CGSize(width: (view.frame.width / 3) - 50, height: (view.frame.width / 3) - 60)
          }
      }
  }
  </code></pre>
  
  <p>The CollectionViewCell:</p>
  
  <pre><code>class HomeCell: UICollectionViewCell {
  
      var themePage = false
      var banner = 0
      var gift = 0
      var teamEvent = 0
      var discount = 1
  
      func configure(with homeEvent: HomeEvent) {
          homeEvent.image {
              (image) in
              self.eventImageView.image = image
          }
          genreLabel.text = homeEvent.genre
          if homeEvent.teamEvent == "0" {
              teamEventLabel.isHidden = true
          }
          else {
              teamEvent = 1
              teamEventLabel.isHidden = false
          }
          if homeEvent.gift == "0" {
              giftLabel.isHidden = true
          }
          else {
              gift = 1
              giftLabel.isHidden = false
          }
          if homeEvent.discount.prefix(1) == "&lt;" {
              let normalText = "Bis zu "
              let boldText = "" + homeEvent.discount.suffix(2) + "%"
              let normalAttributes = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 14)]
              let attributedString = NSMutableAttributedString(string: normalText, attributes: normalAttributes)
              let boldAttributes = [NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 24)]
              let boldString = NSMutableAttributedString(string: boldText, attributes: boldAttributes)
              attributedString.append(boldString)
              variableDiscountLabel.attributedText = attributedString
              fixDiscountLabel.isHidden = true
              discount = 2
          }
          else {
              fixDiscountLabel.text = homeEvent.discount.suffix(2) + "%"
              variableDiscountLabel.isHidden = true
          }
          if homeEvent.bannerText == "" {
              bannerView1.isHidden = true
              bannerView2.isHidden = true
              bannerView3.isHidden = true
              bannerView4.isHidden = true
          }
          else {
              if homeEvent.bannerText == "Angebot endet heute!" {
                  banner = 1
              }
              else if homeEvent.bannerText == "Überregionales Top-Angebot" {
                  banner = 2
              }
              else if homeEvent.bannerText == "Nur noch wenige Tickets" {
                  banner = 3
              }
              else if homeEvent.bannerText == "Angebot endet morgen!" {
                  banner = 4
              }
              else {
                  bannerView1.isHidden = true
                  bannerView2.isHidden = true
                  bannerView3.isHidden = true
                  bannerView4.isHidden = true
              }
          }
          eventTitleLabel.text = homeEvent.title
          eventSubTitleLabel.text = homeEvent.subtitle
          if homeEvent.themePage == "1" {
              themePage = true
              locationImageView.isHidden = true
              eventDatesLabel.isHidden = true
              eventLocationLabel.isHidden = true
          }
          else {
              eventDatesLabel.text = homeEvent.dates
              eventLocationLabel.text = homeEvent.location
          }
          setupViews()
      }
  
      override func prepareForReuse() {
          eventImageView.image = nil
          genreLabel.text = nil
          teamEventLabel.isHidden = true
          giftLabel.isHidden = true
          fixDiscountLabel.text = nil
          variableDiscountLabel.text = nil
          eventTitleLabel.text = nil
          eventSubTitleLabel.text = nil
          eventDatesLabel.text = nil
          eventLocationLabel.text = nil
      }
  
      weak var homeControllerDelegate: HomeControllerDelegate?
  
      override init(frame: CGRect) {
          super.init(frame: frame)
  //        setupViews() //genreLabel just displaying one Letter
      }
  
      func setupViews() {
          addSubview(genreLabel)
          if discount == 1 {
              addSubview(fixDiscountLabel)
          }
          else {
              addSubview(variableDiscountLabel)
          }
  
          //setting Subviews for other labels, views ...
  
          _ = genreLabel.anchor(topAnchor, left: leftAnchor, bottom: nil, right: nil, topConstant: 16, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: genreLabel.intrinsicContentSize.width, heightConstant: 30)
  
          if discount == 1 {
                  _ = fixDiscountLabel.anchor(topAnchor, left: nil, bottom: nil, right: rightAnchor, topConstant: imageHeight - 32, leftConstant: 0, bottomConstant: 0, rightConstant: 8, widthConstant: 64, heightConstant: 64)
  
                  _ = eventTitleLabel.anchor(eventImageView.bottomAnchor, left: leftAnchor, bottom: nil, right: fixDiscountLabel.leftAnchor, topConstant: 6, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: 0, heightConstant: (UIScreen.main.bounds.width - 60 - imageHeight) / 4 - 6)
              }
              else {
                  _ = variableDiscountLabel.anchor(topAnchor, left: nil, bottom: nil, right: rightAnchor, topConstant: imageHeight - 32, leftConstant: 0, bottomConstant: 0, rightConstant: 8, widthConstant: 64, heightConstant: 64)
  
                  _ = eventTitleLabel.anchor(eventImageView.bottomAnchor, left: leftAnchor, bottom: nil, right: variableDiscountLabel.leftAnchor, topConstant: 6, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: 0, heightConstant: (UIScreen.main.bounds.width - 60 - imageHeight) / 4 - 6)
              }
  
          //setting the constraints for other labels, views ...
  
          }
      }
      required init?(coder aDecoder: NSCoder) {
          fatalError("init(coder:) has not been implemented")
      }
  }
  </code></pre>
  
  <p>I want the genreLable to have the width to fit the text and not to change after scrolling. Also the discountLabel should not disappear after scrolling.</p>