自定义底部菜单栏按钮
语聊房 UIKit(Live Audio Room Kit) 支持自定义调整菜单栏的按钮,支持删除默认按钮或添加自定义按钮。您可以删除默认按钮或添加自定义按钮。如果需要,您可以配置bottomMenuBarConfig:
hostButtons
:使用此选项为房主(主持人)设置预制的按钮。speakerButtons
:使用此选项为发言人设置预制的按钮。audienceButtons
:使用此选项为观众设置预制的按钮。
maxCount
:菜单栏可以显示的按钮的最大数量,支持范围设置[1, 5],默认值是 5。
showInRoomMessageButton
:是否显示消息按钮,默认显示。
如果内置按钮和自定义按钮的总数不超过maxCount
个,所有按钮都将正常显示。
若按钮数超过 5 个,超出的其他按钮将隐藏在(⋮)按钮中。单击此按钮将弹出底部面板以显示其他所有按钮。以下是实际效果和参考代码:

Swift
Objective-C
class ViewController: UIViewController {
let selfUserID: String = "userID"
let selfUserName: String = "userName"
let yourAppID: UInt32 = YourAppID // 替换为您的 AppID
let yourAppSign: String = "YourAppSign" // 替换为您的 AppSign
let roomID: String = "YourRoomID" // 替换为您的 RoomID
@IBAction func startLiveAudio(_ sender: Any) {
// 在此处修改您的自定义配置。
let config: ZegoUIKitPrebuiltLiveAudioRoomConfig = ZegoUIKitPrebuiltLiveAudioRoomConfig.host()
config.bottomMenuBarConfig.hostButtons = [.showMemberListButton, .toggleMicrophoneButton]
config.bottomMenuBarConfig.audienceButtons = [.showMemberListButton, .toggleMicrophoneButton]
config.bottomMenuBarConfig.speakerButtons = [.showMemberListButton, .toggleMicrophoneButton]
let liveAudioVC = ZegoUIKitPrebuiltLiveAudioRoomVC.init(yourAppID, appSign: yourAppSign, userID: selfUserID, userName: selfUserName, roomID: roomID, config: config)
liveAudioVC.modalPresentationStyle = .fullScreen
self.present(liveAudioVC, animated: true, completion: nil)
}
}
1
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
unsigned int appID = xxx;
NSString *appSign = @"xxx";
NSString *userName = @"xxx";
NSString *userID = @"xxx";
NSString *roomID = @"xxx";
}
- (void)startLiveAudio {
ZegoUIKitPrebuiltLiveAudioRoomConfig *config = [ZegoUIKitPrebuiltLiveAudioRoomConfig host];
ZegoBottomMenuBarConfig* bottomMenuBarConfig = [[ZegoBottomMenuBarConfig alloc] initWithHostButtons:@[@(ZegoMenuBarButtonNameLeaveButton)] speakerButtons:@[@(ZegoMenuBarButtonNameToggleMicrophoneButton)] audienceButtons:@[@(ZegoMenuBarButtonNameApplyTakeSeatButton)]];
config.bottomMenuBarConfig = bottomMenuBarConfig;
ZegoUIKitPrebuiltLiveAudioRoomVC *vc = [[ZegoUIKitPrebuiltLiveAudioRoomVC alloc] init:appID appSign:appSign userID:userID userName:userName roomID:roomID config:config];
vc.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:vc animated:YES completion:^{
}];
}
1
此外,您也可以通过以下两种方法实现相同的效果:addButtonToMenuBar
和 clearBottomBarExtendButtons
。
Untitled
@objc public func addButtonToMenuBar(_ button: UIButton, role: ZegoLiveAudioRoomRole)
@objc public func clearBottomBarExtendButtons(_ role: ZegoLiveAudioRoomRole)
1