title: How to add label to collection view
body: <p>I want to display a label if there is no post available on a users profile. I have copied a piece of code of an answer on here which is </p>
  
  <pre class="lang-swift prettyprint-override"><code>   func setEmptyMessage(_ message: String) {
          let messageLabel = UILabel(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 30))
  
          messageLabel.text = message
          messageLabel.textColor = .black
          messageLabel.numberOfLines = 0
          messageLabel.textAlignment = .center
          messageLabel.font = UIFont.systemFont(ofSize: 17, weight: .regular)
          messageLabel.sizeToFit()
          messageLabel.clipsToBounds = true
  
          self.collectionView.backgroundView = messageLabel
      }
  
      func restore() {
           self.collectionView.backgroundView = nil
      }
  </code></pre>
  
  <p>In use</p>
  
  <pre class="lang-swift prettyprint-override"><code>    // Return users uploaded posts
      func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
  
          if posts.count == 0 {
              self.setEmptyMessage("No Posts")
          } else {
              self.restore()
          }
          return posts.count 
      }
  </code></pre>
  
  <p>The Code works great, the label displays when it needs to. The only problem is I have a collection view header and when I pull down to refresh   the view of the header mixes with the label. How can I either hide the label when I pull down to refresh or somehow give it a fixed constraint under the section header? Not sure if it would be better to hide the label when I pull down to refresh but I do not know how to grab the code for the emptyMessage and incorporate it with my handleRefresh code..</p>
  
  <pre class="lang-swift prettyprint-override"><code>   @objc func handleRefresh() {
  
          posts.removeAll(keepingCapacity: false)
          self.currentKey = nil
          fetchPosts()
          collectionView?.reloadData()
      }
  
  </code></pre>
  
  <p>Here are two screenshots of what I mean. First photo is where I want the label to stay. </p>
  
  <p><a href="https://i.stack.imgur.com/uwG3s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uwG3s.png" alt="enter image description here"></a></p>
  
  <p><strong>Second Photo</strong> As you can see when I pull down to refresh the label will not stay in place. It kinda goes up with the header. Is this because I have set the message to be apart of the background view?
  <a href="https://i.stack.imgur.com/25YNM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/25YNM.png" alt="enter image description here"></a></p>