如何将标题/自定义视图添加到JSQMessagesViewController?

时间:2017-01-28 05:45:29

标签: ios objective-c swift jsqmessagesviewcontroller

我正在使用故事板来构建我的UI。我无法在Github上的JSQMessageViewController和repo上找到相同问题的同一张票。

基本上,我想添加一个自定义视图,比如我的控制器中的标题,如下所示:

enter image description here

到目前为止我做了什么:

  1. 将视图添加到故事板 - 没有用。
  2. 我以编程方式制作了UICollectionReusableView并将其添加到数据源函数中:viewForSupplementaryElementOfKind
  3. 有什么想法吗?

1 个答案:

答案 0 :(得分:2)

您可以更改任何您喜欢的内容,但这里是如何以编程方式执行此操作。

addViewOnTop()

中致电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)
}

添加UIEdgeInset,以便您在新视图下查看消息 请在viewDidLoad()

中调用此方法
 self.collectionView?.collectionViewLayout.sectionInset = UIEdgeInsets(top: 80, left: 0, bottom: 0, right: 0)
相关问题