WFCUFileCell.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // FileCell.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/9/9.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUFileCell.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import "WFCUUtilities.h"
  11. @implementation WFCUFileCell
  12. + (CGSize)sizeForClientArea:(WFCUMessageModel *)msgModel withViewWidth:(CGFloat)width {
  13. return CGSizeMake(width*4/5, 50);
  14. }
  15. - (void)setModel:(WFCUMessageModel *)model {
  16. [super setModel:model];
  17. WFCCFileMessageContent *fileContent = (WFCCFileMessageContent *)model.message.content;
  18. NSString *ext = [[fileContent.name pathExtension] lowercaseString];
  19. CGRect bounds = self.contentArea.bounds;
  20. if (model.message.direction == MessageDirection_Send) {
  21. self.fileImageView.frame = CGRectMake(bounds.size.width - 40, 4, 36, 42);
  22. self.fileNameLabel.frame = CGRectMake(4, 4, bounds.size.width - 48, 22);
  23. self.sizeLabel.frame = CGRectMake(4, 30, bounds.size.width - 48, 15);
  24. self.sizeLabel.textAlignment = NSTextAlignmentLeft;
  25. } else {
  26. self.fileImageView.frame = CGRectMake(4, 4, 36, 42);
  27. self.fileNameLabel.frame = CGRectMake(44, 4, bounds.size.width - 48, 22);
  28. self.sizeLabel.frame = CGRectMake(44, 30, bounds.size.width - 48, 15);
  29. self.sizeLabel.textAlignment = NSTextAlignmentRight;
  30. }
  31. self.fileImageView.image = [WFCUUtilities imageForExt:ext];
  32. self.fileNameLabel.text = fileContent.name;
  33. self.sizeLabel.text = [WFCUUtilities formatSizeLable:fileContent.size];
  34. }
  35. - (UIView *)getProgressParentView {
  36. return self.fileImageView;
  37. }
  38. - (UIImageView *)fileImageView {
  39. if (!_fileImageView) {
  40. _fileImageView = [[UIImageView alloc] init];
  41. [self.contentArea addSubview:_fileImageView];
  42. }
  43. return _fileImageView;
  44. }
  45. - (UILabel *)fileNameLabel {
  46. if (!_fileNameLabel) {
  47. _fileNameLabel = [[UILabel alloc] init];
  48. _fileNameLabel.font = [UIFont systemFontOfSize:20];
  49. [_fileNameLabel setTextColor:[UIColor blackColor]];
  50. [self.contentArea addSubview:_fileNameLabel];
  51. }
  52. return _fileNameLabel;
  53. }
  54. - (UILabel *)sizeLabel {
  55. if (!_sizeLabel) {
  56. _sizeLabel = [[UILabel alloc] init];
  57. _sizeLabel.font = [UIFont systemFontOfSize:15];
  58. [self.contentArea addSubview:_sizeLabel];
  59. }
  60. return _sizeLabel;
  61. }
  62. @end