Display barrage | Send barrage |
TUIBarrageButton
:Clicking it can bring up the input interface.TUIBarrageDisplayView
:Used for displaying barrage messages.TUIBarrageButton
, which can bring up the input interface when clicked:let barrageButton: TUIBarrageButton = TUIBarrageButton(roomId: xxx)view.addSubview(barrageButton)// layout barrageButton
TUIBarrageDisplayView
to show the barrage messages:let barrageDisplayView: TUIBarrageDisplayView = TUIBarrageDisplayView(roomId: xxx) view.addSubview(barrageDisplayView)// layout barrageDisplayView
createCustomCell
delegate function in the TUIBarrageDisplayViewDelegate
of TUIBarrageDisplayView
, which is used to customize the barrage message style.barrageDisplayView.delegate = selfextension UIViewController: TUIBarrageDisplayViewDelegate {func barrageDisplayView(_ barrageDisplayView: TUIBarrageDisplayView, createCustomCell barrage: TUIBarrage) -> UIView? {// Return custom barrage UI here.}}
TUIBarrageDisplayView
will first call the delegate function barrageDisplayView:createCustomCell
to obtain the user's custom style for a specific barrage message. If it returns nil, the default barrage style of TUIBarrageDisplayView will be used.TUIBarrageDisplayView
provides the external interface method insertBarrages
for inserting custom messages (in batches). Custom messages are usually used in combination with custom styles to achieve different display effects.// Example: Insert a gift message in the barrage area.let barrage = TUIBarrage() barrage.content = "gift" barrage.user.userId = sender.userId barrage.user.userName = sender.userName barrage.user.avatarUrl = sender.avatarUrl barrage.user.level = sender.level barrage.extInfo["xxx"] = "xxx" barrageDisplayView.insertBarrages(barrage);
extInfo
of TUIBarrage
is a Map, used for storing custom data.
Was this page helpful?