123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- //
- // EMMsgFileBubbleView.m
- // ChatDemo-UI3.0
- //
- // Created by XieYajie on 2019/2/14.
- // Copyright © 2019 XieYajie. All rights reserved.
- //
- #import "EMMsgFileBubbleView.h"
- @implementation EMMsgFileBubbleView
- - (instancetype)initWithDirection:(EMMessageDirection)aDirection
- type:(EMMessageType)aType
- {
- self = [super initWithDirection:aDirection type:aType];
- if (self) {
- [self _setupSubviews];
- }
-
- return self;
- }
- #pragma mark - Subviews
- - (void)_setupSubviews
- {
- [self setupBubbleBackgroundImage];
-
- self.iconView = [[UIImageView alloc] init];
- self.iconView.contentMode = UIViewContentModeScaleAspectFit;
- self.iconView.clipsToBounds = YES;
- [self addSubview:self.iconView];
-
- self.textLabel = [[UILabel alloc] init];
- self.textLabel.font = [UIFont systemFontOfSize:18];
- self.textLabel.numberOfLines = 0;
- [self addSubview:self.textLabel];
-
- self.detailLabel = [[UILabel alloc] init];
- self.detailLabel.font = [UIFont systemFontOfSize:15];
- self.detailLabel.numberOfLines = 0;
- [self addSubview:self.detailLabel];
- [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.textLabel.mas_bottom);
- make.bottom.equalTo(self).offset(-10);
- make.left.equalTo(self.textLabel);
- make.right.equalTo(self.textLabel);
- }];
-
- if (self.direction == EMMessageDirectionSend) {
- self.iconView.image = [UIImage imageNamed:@"msg_file_white"];
- [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self).offset(10);
- make.left.equalTo(self).offset(5);
- make.centerY.equalTo(self);
- make.width.equalTo(@40);
- }];
-
- self.textLabel.textColor = [UIColor whiteColor];
- [self.textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self).offset(10);
- make.left.equalTo(self.iconView.mas_right).offset(5);
- make.right.equalTo(self).offset(-15);
- }];
-
- self.detailLabel.textColor = [UIColor colorWithWhite:0.8 alpha:1.0];
- } else {
- self.iconView.image = [UIImage imageNamed:@"msg_file"];
- [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self).offset(10);
- make.left.equalTo(self).offset(8);
- make.centerY.equalTo(self);
- make.width.equalTo(@40);
- }];
-
- self.textLabel.textColor = [UIColor blackColor];
- [self.textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self).offset(10);
- make.left.equalTo(self.iconView.mas_right).offset(5);
- make.right.equalTo(self).offset(-10);
- }];
-
- self.detailLabel.textColor = [UIColor grayColor];
- }
- }
- #pragma mark - Setter
- - (void)setModel:(EMMessageModel *)model
- {
- EMMessageType type = model.type;
- if (type == EMMessageTypeFile) {
- EMFileMessageBody *body = (EMFileMessageBody *)model.emModel.body;
- self.textLabel.text = body.displayName;
- self.detailLabel.text = [NSString stringWithFormat:@"%.2lf MB",(float)body.fileLength / (1024 * 1024)];
- }
- }
- @end
|