86 lines
2.4 KiB
Mathematica
86 lines
2.4 KiB
Mathematica
|
|
//
|
|||
|
|
// KBChatUserCell.m
|
|||
|
|
// CustomKeyboard
|
|||
|
|
//
|
|||
|
|
// 用户消息 Cell(右侧显示)
|
|||
|
|
//
|
|||
|
|
|
|||
|
|
#import "KBChatUserCell.h"
|
|||
|
|
#import "KBChatMessage.h"
|
|||
|
|
#import "Masonry.h"
|
|||
|
|
|
|||
|
|
@interface KBChatUserCell ()
|
|||
|
|
|
|||
|
|
@property (nonatomic, strong) UIView *bubbleView;
|
|||
|
|
@property (nonatomic, strong) UILabel *messageLabel;
|
|||
|
|
|
|||
|
|
@end
|
|||
|
|
|
|||
|
|
@implementation KBChatUserCell
|
|||
|
|
|
|||
|
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style
|
|||
|
|
reuseIdentifier:(NSString *)reuseIdentifier {
|
|||
|
|
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
|
|||
|
|
if (self) {
|
|||
|
|
self.backgroundColor = [UIColor clearColor];
|
|||
|
|
self.contentView.backgroundColor = [UIColor clearColor];
|
|||
|
|
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
|||
|
|
[self setupUI];
|
|||
|
|
}
|
|||
|
|
return self;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)setupUI {
|
|||
|
|
[self.contentView addSubview:self.bubbleView];
|
|||
|
|
[self.bubbleView addSubview:self.messageLabel];
|
|||
|
|
|
|||
|
|
[self.bubbleView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|||
|
|
make.top.equalTo(self.contentView).offset(4);
|
|||
|
|
make.bottom.equalTo(self.contentView).offset(-4);
|
|||
|
|
make.right.equalTo(self.contentView).offset(-12);
|
|||
|
|
make.width.lessThanOrEqualTo(self.contentView).multipliedBy(0.7);
|
|||
|
|
make.height.greaterThanOrEqualTo(@36);
|
|||
|
|
}];
|
|||
|
|
|
|||
|
|
[self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|||
|
|
make.top.equalTo(self.bubbleView).offset(8);
|
|||
|
|
make.bottom.equalTo(self.bubbleView).offset(-8);
|
|||
|
|
make.left.equalTo(self.bubbleView).offset(12);
|
|||
|
|
make.right.equalTo(self.bubbleView).offset(-12);
|
|||
|
|
}];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)configureWithMessage:(KBChatMessage *)message {
|
|||
|
|
self.messageLabel.text = message.text ?: @"";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)prepareForReuse {
|
|||
|
|
[super prepareForReuse];
|
|||
|
|
self.messageLabel.text = @"";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#pragma mark - Lazy
|
|||
|
|
|
|||
|
|
- (UIView *)bubbleView {
|
|||
|
|
if (!_bubbleView) {
|
|||
|
|
_bubbleView = [[UIView alloc] init];
|
|||
|
|
_bubbleView.backgroundColor = [UIColor colorWithHex:0x02BEAC];
|
|||
|
|
_bubbleView.layer.cornerRadius = 12;
|
|||
|
|
_bubbleView.layer.masksToBounds = YES;
|
|||
|
|
}
|
|||
|
|
return _bubbleView;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (UILabel *)messageLabel {
|
|||
|
|
if (!_messageLabel) {
|
|||
|
|
_messageLabel = [[UILabel alloc] init];
|
|||
|
|
_messageLabel.numberOfLines = 0;
|
|||
|
|
_messageLabel.font = [UIFont systemFontOfSize:14];
|
|||
|
|
_messageLabel.textColor = [UIColor whiteColor];
|
|||
|
|
_messageLabel.lineBreakMode = NSLineBreakByWordWrapping;
|
|||
|
|
}
|
|||
|
|
return _messageLabel;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@end
|