2025-10-29 16:26:57 +08:00
|
|
|
//
|
|
|
|
|
// KBGuideUserCell.m
|
|
|
|
|
// keyBoard
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "KBGuideUserCell.h"
|
2025-12-15 17:56:06 +08:00
|
|
|
#import "KBUserSessionManager.h"
|
|
|
|
|
#import "KBUser.h"
|
2025-10-29 16:26:57 +08:00
|
|
|
|
|
|
|
|
@interface KBGuideUserCell ()
|
2025-12-15 17:56:06 +08:00
|
|
|
@property (nonatomic, strong) UIImageView *avatarImageView; // 右侧用户头像
|
2025-10-29 16:26:57 +08:00
|
|
|
@property (nonatomic, strong) UIView *bubbleView; // 右侧紫色气泡
|
|
|
|
|
@property (nonatomic, strong) UILabel *contentLabel;
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation KBGuideUserCell
|
|
|
|
|
|
|
|
|
|
- (void)setupUI {
|
|
|
|
|
self.contentView.backgroundColor = [UIColor colorWithWhite:0.96 alpha:1.0];
|
|
|
|
|
|
2025-12-15 17:56:06 +08:00
|
|
|
[self.contentView addSubview:self.avatarImageView];
|
|
|
|
|
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.right.equalTo(self.contentView).offset(-16);
|
|
|
|
|
make.top.equalTo(self.contentView).offset(10);
|
|
|
|
|
make.width.height.mas_equalTo(36);
|
|
|
|
|
}];
|
|
|
|
|
|
2025-10-29 16:26:57 +08:00
|
|
|
[self.contentView addSubview:self.bubbleView];
|
|
|
|
|
[self.bubbleView mas_makeConstraints:^(MASConstraintMaker *make) {
|
2025-12-15 17:56:06 +08:00
|
|
|
make.right.equalTo(self.avatarImageView.mas_left).offset(-8);
|
2025-10-29 16:26:57 +08:00
|
|
|
make.top.equalTo(self.contentView).offset(8);
|
|
|
|
|
make.left.greaterThanOrEqualTo(self.contentView).offset(80);
|
|
|
|
|
make.bottom.equalTo(self.contentView).offset(-8);
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
[self.bubbleView addSubview:self.contentLabel];
|
|
|
|
|
[self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.edges.equalTo(self.bubbleView).insets(UIEdgeInsetsMake(8, 10, 8, 10));
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)configText:(NSString *)text {
|
|
|
|
|
self.contentLabel.text = text;
|
2025-12-15 17:56:06 +08:00
|
|
|
self.avatarImageView.image = [self kb_resolvedAvatarImage];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - Helpers
|
|
|
|
|
|
|
|
|
|
- (UIImage *)kb_resolvedAvatarImage {
|
|
|
|
|
UIImage *placeholder = [UIImage imageNamed:@"placeholder_icon"];
|
|
|
|
|
|
|
|
|
|
KBUserSessionManager *session = [KBUserSessionManager shared];
|
|
|
|
|
if (![session isLoggedIn]) {
|
|
|
|
|
return placeholder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
KBUser *user = session.currentUser;
|
|
|
|
|
if (!user) {
|
|
|
|
|
return placeholder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (user.gender) {
|
|
|
|
|
case UserSexMan:
|
|
|
|
|
return [UIImage imageNamed:@"message_man_icon"] ?: placeholder;
|
|
|
|
|
case UserSexWeman:
|
|
|
|
|
return [UIImage imageNamed:@"message_nv_icon"] ?: placeholder;
|
|
|
|
|
default:
|
|
|
|
|
return placeholder;
|
|
|
|
|
}
|
2025-10-29 16:26:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - Lazy
|
|
|
|
|
|
2025-12-15 17:56:06 +08:00
|
|
|
- (UIImageView *)avatarImageView {
|
|
|
|
|
if (!_avatarImageView) {
|
|
|
|
|
_avatarImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"placeholder_icon"]];
|
|
|
|
|
_avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
|
|
|
_avatarImageView.layer.cornerRadius = 18;
|
|
|
|
|
_avatarImageView.layer.masksToBounds = YES;
|
|
|
|
|
}
|
|
|
|
|
return _avatarImageView;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-29 16:26:57 +08:00
|
|
|
- (UIView *)bubbleView {
|
|
|
|
|
if (!_bubbleView) {
|
|
|
|
|
_bubbleView = [UIView new];
|
2025-12-15 17:56:06 +08:00
|
|
|
_bubbleView.backgroundColor = [UIColor colorWithHex:KBColorValue];
|
2025-10-29 16:26:57 +08:00
|
|
|
_bubbleView.layer.cornerRadius = 12;
|
|
|
|
|
_bubbleView.layer.masksToBounds = YES;
|
|
|
|
|
}
|
|
|
|
|
return _bubbleView;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (UILabel *)contentLabel {
|
|
|
|
|
if (!_contentLabel) {
|
|
|
|
|
_contentLabel = [UILabel new];
|
|
|
|
|
_contentLabel.numberOfLines = 0;
|
2025-11-25 15:36:16 +08:00
|
|
|
_contentLabel.font = [KBFont medium:16];
|
2025-10-29 16:26:57 +08:00
|
|
|
_contentLabel.textColor = [UIColor whiteColor];
|
|
|
|
|
_contentLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
|
}
|
|
|
|
|
return _contentLabel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|