Files
keyboard/keyBoard/Class/Guard/V/KBGuideUserCell.m
2025-12-15 17:56:06 +08:00

106 lines
3.1 KiB
Objective-C

//
// KBGuideUserCell.m
// keyBoard
//
#import "KBGuideUserCell.h"
#import "KBUserSessionManager.h"
#import "KBUser.h"
@interface KBGuideUserCell ()
@property (nonatomic, strong) UIImageView *avatarImageView; // 右侧用户头像
@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];
[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);
}];
[self.contentView addSubview:self.bubbleView];
[self.bubbleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.avatarImageView.mas_left).offset(-8);
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;
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;
}
}
#pragma mark - Lazy
- (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;
}
- (UIView *)bubbleView {
if (!_bubbleView) {
_bubbleView = [UIView new];
_bubbleView.backgroundColor = [UIColor colorWithHex:KBColorValue];
_bubbleView.layer.cornerRadius = 12;
_bubbleView.layer.masksToBounds = YES;
}
return _bubbleView;
}
- (UILabel *)contentLabel {
if (!_contentLabel) {
_contentLabel = [UILabel new];
_contentLabel.numberOfLines = 0;
_contentLabel.font = [KBFont medium:16];
_contentLabel.textColor = [UIColor whiteColor];
_contentLabel.textAlignment = NSTextAlignmentCenter;
}
return _contentLabel;
}
@end