如何自定义聊天页面右下角 unReadNewMessageLabel 控件

如何自定义 RCConversationViewController 页面的下列属性 /*! 右下角未读消息数提示的 Label */ @property(nonatomic, strong) UILabel *unReadNewMessageLabel;
发布时间: 2019-07-12 17:03

回答:

1.聊天页子类添加属性:@property (nonatomic, strong) UIImageView *unreadRightBottomIcon;


2.在聊天页的子页面添加以下方法,部分内容可以根据自己的需求进行更改:


@synthesize unReadNewMessageLabel = _unReadNewMessageLabel;
- (UILabel *)unReadNewMessageLabel {
    if (!_unReadNewMessageLabel) {
        _unReadNewMessageLabel = [[UILabel alloc] initWithFrame:_unreadRightBottomIcon.bounds];
        _unReadNewMessageLabel.backgroundColor = [UIColor clearColor];
        _unReadNewMessageLabel.font = [UIFont systemFontOfSize:12.0f];
        _unReadNewMessageLabel.textAlignment = NSTextAlignmentCenter;
        _unReadNewMessageLabel.textColor = [UIColor redColor];
        _unReadNewMessageLabel.center = CGPointMake(_unReadNewMessageLabel.frame.size.width / 2,
                                                    _unReadNewMessageLabel.frame.size.height / 2 - 2.5);
        [self.unreadRightBottomIcon addSubview:_unReadNewMessageLabel];
    }
    return _unReadNewMessageLabel;
}
- (UIImageView *)unreadRightBottomIcon {
    if (!_unreadRightBottomIcon) {
        UIImage *msgCountIcon = [RCKitUtility imageNamed:@"bubble" ofBundle:@"RongCloud.bundle"];
        _unreadRightBottomIcon = [[UIImageView alloc]
                                  initWithFrame:CGRectMake(self.view.frame.size.width - 5.5 - 35,
                                                           self.chatSessionInputBarControl.frame.origin.y - 12 - 35, 35, 35)];
        _unreadRightBottomIcon.userInteractionEnabled = YES;
        _unreadRightBottomIcon.image = msgCountIcon;
        UITapGestureRecognizer *tap =
        [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tabRightBottomMsgCountIcon:)];
        [_unreadRightBottomIcon addGestureRecognizer:tap];
        _unreadRightBottomIcon.hidden = YES;
        [self.view addSubview:_unreadRightBottomIcon];
    }
    return _unreadRightBottomIcon;
}