-
Notifications
You must be signed in to change notification settings - Fork 11
自定义联系人列表

-
在Demo中继承EaseChatUIKit中的
EaseChatNavigationBar类创建自己的会话列表页面导航,这里示例命名为CustomConversationNavigationBar. -
重载
createNavigation()方法并返回您使用CustomConversationNavigationBar创建的对象。示例代码如下:
override func createNavigationBar() -> EaseChatNavigationBar {
CustomConversationNavigationBar(showLeftItem: false,rightImages: [UIImage(named: "add", in: .chatBundle, with: nil,hiddenAvatar: false)
}-
自定义导航栏右侧按钮的显示图片,在上面代码
rightImages中返回您想要的图片即可,注意按照顺序分别是0,1,2。是否显示导航左侧的头像上面代码中hiddenAvatar参数即可控制。 -
自定义导航后以及原来的导航点击事件的监听,需要您重载会话列表页面中的
navigationClick方法,然后根据对应的点击区域做对应的处理,示例代码如下:
override func navigationClick(type: EaseChatNavigationBarClickEvent, indexPath: IndexPath?) {
switch type {
case .back: self.backAction()
case .avatar: self.avatarAction()
case .title: self.titleAction()
case .subtitle: self.subtitleAction()
case .rightItems: self.rightItemsAction(indexPath: indexPath)
default:
break
}
}
-
导航栏的编辑模式可以设置
editMode = true实现,表现为返回按钮被隐藏,右侧三个按钮会被隐藏,右侧出现一个取消按钮 -
更改导航标题内容可通过
self.navigation.title = "Chats".chat.localize实现,同理导航的子标题self.navigation.subtitle = "xxx"实现类似,但是需要注意的是,在设置标题之前需要先设置子标题,除非没有子标题可以直接设置标题。先设置子标题再设置标题是为了更新内中对应的布局位置(如果二者都有的话)。 -
更改导航头像可通过
self.navigation.avatarURL = "https://xxx.xxx.xxx"实现 -
设置导航以及背景颜色可以通过
self.navigation.backgroudColor = .red实现,导航内部组件也可支持此种方式修改,前提是在不切换主题的情况下,如果在切换主题的时候会切换为主题默认的颜色。
- 自定义会话列表TableView,需要重载会话列表页面中的
createContactList方法后,返回您继承EaseChatUIKit中ContactView后的类对象,具体内中实现业务逻辑需要您找到ContactView.swift类中仔细查看,示例代码如下:
override open func createContactList() -> ContactView {
CustomContactView(frame: CGRect(x: 0, y: self.search.frame.maxY+5, width: self.view.frame.width, height: self.view.frame.height-NavigationHeight-BottomBarHeight-(self.tabBarController?.tabBar.frame.height ?? 49)), style: .plain)
}- 自定义联系人列表中的列表项中的内容,即
ContactCell。您需要继承EaseChatUIKit中的ContactCell类创建新的自定义类CustomContactCell,然后进行如下代码设置:
ComponentsRegister.shared.ContactsCell = CustomContactCell.self然后在CustomContactCell 类中,重载对应可以重载的方法,如果需要复用已有的逻辑在此基础上进行新增的逻辑则只需要重载某个方法后调用super.xxx即可,举例:
override open func refresh(profile: EaseProfileProtocol) {
super.refresh(profile: profile)
//继续您的新逻辑即可
}如果需要对之前逻辑做改动,则需要将之前refresh 方法中的代码复制过来后,进行改动,不需要调用super.xxxx。初始化方法以及部分UI创建的方法均可以重载。
- 其他标记为open的方法均为可重载方法,如用户有需要重载对应方法实现自己业务逻辑即可。
- 联系人列表Header中的数据源项
Appearance.contact.listHeaderExtensionActions,下面示例如何增减:
//Add
Appearance.contact.listHeaderExtensionActions.append(ContactListHeaderItem(featureIdentify: "New", featureName: "NewFeature", featureIcon: UIImage(named: "NewFeature")))
//Remove
Appearance.contact.listHeaderExtensionActions.removeAll { $0.featureIdentify == "you want remove" }获取该数组中某单个项的点击事件,示例:
if let item = Appearance.contact.listHeaderExtensionActions.first(where: { $0.featureIdentify == "NewFriendRequest" }) {
item.actionClosure = { [weak self] _ in
//do something
}
}
if let item = Appearance.contact.listHeaderExtensionActions.first(where: { $0.featureIdentify == "GroupChats" }) {
item.actionClosure = { [weak self] _ in
//do something
}
}