title: Programmatically setup headerviews
body: <p>I know how to add headers to UICollectionViews however I don't know how to customize them. The method I know is similar to customizing UICollectionViewCells however I probably am missing a few subclasses and some required setup code, because when I cast my header as this class it fails...</p>
  
  <pre><code>class LiveHeader: UICollectionReusableView {
  
  
  }  
  </code></pre>
  
  <p>There has to be some required initialization code or something but I haven't found any examples online. Most do this using storyboards.</p>
  
  <p>Any suggestions?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code>//reuse identifier.
  
  let LiveHeaderId = "LiveHeaderId"
  
  //viewDidLoad
  override func viewDidLoad() {
      super.viewDidLoad()
  
      setupCollectionView()
  
      //Register Headers
      collectionView?.register(UICollectionViewCell.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: LiveHeaderId)
      //Register Cells
      collectionView?.register(LiveCell.self, forCellWithReuseIdentifier: LiveCellId)
  
  }
  </code></pre>
  
  <p>Here is where I setup the header view</p>
  
  <pre><code>override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -&gt; UICollectionReusableView {
      let liveHeader = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: LiveHeaderId, for: indexPath) as! LiveHeader
      liveHeader.backgroundColor = UIColor.clear
      /*
      //Here I ended up creating the view because I couldn't get the cast to work. This is my opinion clutters ups the code especially because I eventually want to register more headers
      let container: UIView = {
          let c = UIView()
          c.translatesAutoresizingMaskIntoConstraints = false
          c.backgroundColor = UIColor.clear
          return c
  
      }()
  
      let labelContainer: UIView = {
          let lc = UIView()
          lc.translatesAutoresizingMaskIntoConstraints = false
  //            lc.backgroundColor = UIColor.init(red: 168/255, green: 250/255, blue: 0, alpha: 1)
          lc.backgroundColor = UIColor.init(red: 77/255, green: 182/255, blue: 172/255, alpha: 1)
          lc.layer.cornerRadius = 5
          return lc
      }()
  
      let label: UILabel = {
          let l = UILabel()
          l.text = "LIVE"
          l.font = UIFont.boldSystemFont(ofSize: 15)
          l.textAlignment = .center
          l.translatesAutoresizingMaskIntoConstraints = false
          l.textColor = UIColor.white
          return l
      }()
  
      liveHeader.addSubview(container)
      liveHeader.addConstraintsWithFormat("H:|[v0]|", views: container)
      liveHeader.addConstraintsWithFormat("V:|[v0]|", views: container)
  
  
      container.addSubview(labelContainer)
      labelContainer.widthAnchor.constraint(equalTo: container.widthAnchor, multiplier: 0.1).isActive = true
      labelContainer.heightAnchor.constraint(equalTo: container.heightAnchor, multiplier: 0.5).isActive = true
      labelContainer.centerYAnchor.constraint(equalTo: container.centerYAnchor).isActive = true
      NSLayoutConstraint(item: labelContainer, attribute: .centerX, relatedBy: .equal, toItem: container, attribute: .centerX, multiplier: 0.25, constant: 0).isActive = true
  
  
      labelContainer.addSubview(label)
      labelContainer.addConstraintsWithFormat("H:|[v0]|", views: label)
      labelContainer.addConstraintsWithFormat("V:|[v0]|", views: label)
  
  
  
      return liveHeader
  } */
  
  
  //header size
  
  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -&gt; CGSize {
     return CGSize(width: view.frame.width, height: view.frame.height / 16)
  }
  </code></pre>
  
  <p>If anything I believe I might be missing something in my 'viewForSupplementaryElementOfKind`</p>