EMMsgFileBubbleView.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // EMMsgFileBubbleView.m
  3. // ChatDemo-UI3.0
  4. //
  5. // Created by XieYajie on 2019/2/14.
  6. // Copyright © 2019 XieYajie. All rights reserved.
  7. //
  8. #import "EMMsgFileBubbleView.h"
  9. @implementation EMMsgFileBubbleView
  10. - (instancetype)initWithDirection:(EMMessageDirection)aDirection
  11. type:(EMMessageType)aType
  12. {
  13. self = [super initWithDirection:aDirection type:aType];
  14. if (self) {
  15. [self _setupSubviews];
  16. }
  17. return self;
  18. }
  19. #pragma mark - Subviews
  20. - (void)_setupSubviews
  21. {
  22. [self setupBubbleBackgroundImage];
  23. self.iconView = [[UIImageView alloc] init];
  24. self.iconView.contentMode = UIViewContentModeScaleAspectFit;
  25. self.iconView.clipsToBounds = YES;
  26. [self addSubview:self.iconView];
  27. self.textLabel = [[UILabel alloc] init];
  28. self.textLabel.font = [UIFont systemFontOfSize:18];
  29. self.textLabel.numberOfLines = 0;
  30. [self addSubview:self.textLabel];
  31. self.detailLabel = [[UILabel alloc] init];
  32. self.detailLabel.font = [UIFont systemFontOfSize:15];
  33. self.detailLabel.numberOfLines = 0;
  34. [self addSubview:self.detailLabel];
  35. [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.top.equalTo(self.textLabel.mas_bottom);
  37. make.bottom.equalTo(self).offset(-10);
  38. make.left.equalTo(self.textLabel);
  39. make.right.equalTo(self.textLabel);
  40. }];
  41. if (self.direction == EMMessageDirectionSend) {
  42. self.iconView.image = [UIImage imageNamed:@"msg_file_white"];
  43. [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.top.equalTo(self).offset(10);
  45. make.left.equalTo(self).offset(5);
  46. make.centerY.equalTo(self);
  47. make.width.equalTo(@40);
  48. }];
  49. self.textLabel.textColor = [UIColor whiteColor];
  50. [self.textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.top.equalTo(self).offset(10);
  52. make.left.equalTo(self.iconView.mas_right).offset(5);
  53. make.right.equalTo(self).offset(-15);
  54. }];
  55. self.detailLabel.textColor = [UIColor colorWithWhite:0.8 alpha:1.0];
  56. } else {
  57. self.iconView.image = [UIImage imageNamed:@"msg_file"];
  58. [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.top.equalTo(self).offset(10);
  60. make.left.equalTo(self).offset(8);
  61. make.centerY.equalTo(self);
  62. make.width.equalTo(@40);
  63. }];
  64. self.textLabel.textColor = [UIColor blackColor];
  65. [self.textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.top.equalTo(self).offset(10);
  67. make.left.equalTo(self.iconView.mas_right).offset(5);
  68. make.right.equalTo(self).offset(-10);
  69. }];
  70. self.detailLabel.textColor = [UIColor grayColor];
  71. }
  72. }
  73. #pragma mark - Setter
  74. - (void)setModel:(EMMessageModel *)model
  75. {
  76. EMMessageType type = model.type;
  77. if (type == EMMessageTypeFile) {
  78. EMFileMessageBody *body = (EMFileMessageBody *)model.emModel.body;
  79. self.textLabel.text = body.displayName;
  80. self.detailLabel.text = [NSString stringWithFormat:@"%.2lf MB",(float)body.fileLength / (1024 * 1024)];
  81. }
  82. }
  83. @end