1

I'm using a storyboard to build my UIs. I wasn't able to find same ticket with same question on JSQMessageViewController's repo on Github.

Basically, I want to add a custom view, say a header in my controller, like so:

enter image description here

What I did so far:

  1. Add the view to the storyboard - didn't work.
  2. I programmatically made a UICollectionReusableView and add it to the data source function: viewForSupplementaryElementOfKind

Any ideas?

Community
  • 1
  • 1
Citus
  • 331
  • 1
  • 5
  • 14

1 Answers1

2

You can change anything you like but here is how to do it very simply programatically.

call addViewOnTop() this in your viewDidLoad

func addViewOnTop() {
    let selectableView = UIView(frame: CGRect(x: 0, y: 60, width: self.view.bounds.width, height: 40))
    selectableView.backgroundColor = .red
    let randomViewLabel = UILabel(frame: CGRect(x: 20, y: 10, width: 100, height: 16))
    randomViewLabel.text = "RandomView"
    selectableView.addSubview(randomViewLabel)
    view.addSubview(selectableView)
}

Add an UIEdgeInset to let you view your messages under the new view Call this in the viewDidLoad()

 self.collectionView?.collectionViewLayout.sectionInset = UIEdgeInsets(top: 80, left: 0, bottom: 0, right: 0)
Dan Leonard
  • 3,325
  • 1
  • 20
  • 32