如何在Swift中集自定义JSQMessageMedia?

时间:2016-03-27 19:30:13

标签: swift jsqmessagesviewcontroller

我正在尝试向JSQMessagesViewController添加系统消息。我选择将其实现为JSQMessageMedia。它在视图中显示,但我很难集中它。

系统消息类:

class ChatSystemMessage: NSObject, JSQMessageMediaData {


@objc func mediaView() -> UIView! {
    let mediaView = UIView()
    let label = UILabel(frame: CGRectMake(0, 0, 200, 21))
    label.center = mediaView.center
    label.textAlignment = NSTextAlignment.Center
    label.text = "I'am a test label"
    mediaView.addSubview(label)
    return mediaView
}

@objc func mediaViewDisplaySize() -> CGSize {
    let size = CGSizeMake(200, 21)
    return size
}

@objc func mediaPlaceholderView() -> UIView! {
    return nil
}

@objc func mediaHash() -> UInt {
    return UInt(self.hash)
}
}

它的外观如下:

enter image description here

如何将邮件置于cellForItemAtIndexPath方法中心?我不知道如何访问label中程序化创建的mediaView

0 个答案:

没有答案