157 lines
5.4 KiB
Objective-C
157 lines
5.4 KiB
Objective-C
//
|
|
// XPSessionMessageHeadView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by GreenLand on 2022/3/11.
|
|
//
|
|
|
|
#import "XPSessionMessageHeadView.h"
|
|
#import "NetImageView.h"
|
|
#import <Masonry/Masonry.h>
|
|
#import "ThemeColor.h"
|
|
|
|
@interface XPSessionMessageHeadView()
|
|
|
|
///背景
|
|
@property (nonatomic, strong) UIImageView *backImageView;
|
|
///头像
|
|
@property (nonatomic, strong) NetImageView *avatarImageView;
|
|
///昵称
|
|
@property (nonatomic, strong) UILabel *nickLabel;
|
|
///描述
|
|
@property (nonatomic, strong) UILabel *detailLabel;
|
|
///跟随进房
|
|
@property (nonatomic, strong) UIButton *followButton;
|
|
|
|
@end
|
|
|
|
@implementation XPSessionMessageHeadView
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
if (self = [super initWithFrame:frame]) {
|
|
[self initSubVeiws];
|
|
[self initContraints];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)initSubVeiws {
|
|
[self addSubview:self.backImageView];
|
|
[self addSubview:self.avatarImageView];
|
|
[self addSubview:self.nickLabel];
|
|
[self addSubview:self.detailLabel];
|
|
[self addSubview:self.followButton];
|
|
}
|
|
|
|
- (void)initContraints {
|
|
[self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.mas_equalTo(self).inset(15);
|
|
make.top.mas_equalTo(0);
|
|
make.bottom.mas_equalTo(0);
|
|
}];
|
|
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.backImageView).mas_offset(8);
|
|
make.centerY.mas_equalTo(self.backImageView);
|
|
make.width.height.mas_equalTo(56);
|
|
}];
|
|
[self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.avatarImageView.mas_right).mas_offset(9);
|
|
make.bottom.mas_equalTo(self.avatarImageView.mas_centerY).mas_offset(-3.5);
|
|
make.height.mas_equalTo(18);
|
|
make.right.mas_equalTo(self.followButton.mas_left).mas_offset(-12);
|
|
}];
|
|
[self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.nickLabel);
|
|
make.top.mas_equalTo(self.nickLabel.mas_bottom).mas_offset(7);
|
|
make.height.mas_equalTo(14);
|
|
make.right.mas_equalTo(self.followButton.mas_left).mas_offset(-12);
|
|
}];
|
|
[self.followButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.mas_equalTo(self.backImageView).mas_offset(-7);
|
|
make.centerY.mas_equalTo(self.backImageView);
|
|
make.width.mas_equalTo(82);
|
|
make.height.mas_equalTo(26);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - event
|
|
- (void)onFollowButtonClick:(UIButton *)sender {
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(onFollowInRoom:)]) {
|
|
[self.delegate onFollowInRoom:self.userInfo.roomUid];
|
|
}
|
|
}
|
|
|
|
- (void)onAvatarClick:(UITapGestureRecognizer *)ges {
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(onAvatarClick:)]) {
|
|
[self.delegate onAvatarClick:self.userInfo.uid];
|
|
}
|
|
}
|
|
|
|
- (void)setUserInfo:(UserInfoModel *)userInfo {
|
|
_userInfo = userInfo;
|
|
self.avatarImageView.imageUrl = userInfo.avatar;
|
|
self.nickLabel.text = userInfo.nick;
|
|
NSString *roomTitle = userInfo.roomTitle;
|
|
if (roomTitle.length > 5) {
|
|
roomTitle = [NSString stringWithFormat:@"%@…", [userInfo.roomTitle substringToIndex:5]];
|
|
}
|
|
self.detailLabel.text = [NSString stringWithFormat:@"正在“%@”热聊中", roomTitle];
|
|
}
|
|
|
|
#pragma mark - getter
|
|
- (UIImageView *)backImageView {
|
|
if (!_backImageView) {
|
|
_backImageView = [[UIImageView alloc] init];
|
|
_backImageView.image = [UIImage imageNamed:@"session_follow_background"];
|
|
_backImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
_backImageView.layer.masksToBounds = YES;
|
|
_backImageView.layer.cornerRadius = 6;
|
|
}
|
|
return _backImageView;
|
|
}
|
|
|
|
- (NetImageView *)avatarImageView {
|
|
if (!_avatarImageView) {
|
|
_avatarImageView = [[NetImageView alloc] init];
|
|
_avatarImageView.layer.masksToBounds = YES;
|
|
_avatarImageView.layer.cornerRadius = 28;
|
|
_avatarImageView.image = [UIImageConstant defaultAvatarPlaceholder];
|
|
_avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
_avatarImageView.userInteractionEnabled = YES;
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onAvatarClick:)];
|
|
[_avatarImageView addGestureRecognizer:tap];
|
|
}
|
|
return _avatarImageView;;
|
|
}
|
|
|
|
- (UILabel *)nickLabel {
|
|
if (!_nickLabel) {
|
|
_nickLabel = [[UILabel alloc] init];
|
|
_nickLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
|
|
_nickLabel.textColor = [ThemeColor mainTextColor];
|
|
}
|
|
return _nickLabel;
|
|
}
|
|
|
|
- (UILabel *)detailLabel {
|
|
if (!_detailLabel) {
|
|
_detailLabel = [[UILabel alloc] init];
|
|
_detailLabel.font = [UIFont systemFontOfSize:14];
|
|
_detailLabel.textColor = [ThemeColor secondTextColor];
|
|
}
|
|
return _detailLabel;
|
|
}
|
|
|
|
- (UIButton *)followButton {
|
|
if (!_followButton) {
|
|
_followButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_followButton setTitle:@"跟随进房" forState:UIControlStateNormal];
|
|
[_followButton setBackgroundImage:[UIImage imageNamed:@"session_follow_inRoom"] forState:UIControlStateNormal];
|
|
_followButton.titleLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
|
|
[_followButton addTarget:self action:@selector(onFollowButtonClick:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _followButton;
|
|
}
|
|
|
|
@end
|