downLoadPreViewCell.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. //
  2. // downLoadPreViewCell.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2024/1/8.
  6. //
  7. #import "downLoadPreViewCell.h"
  8. @implementation downLoadPreViewCell
  9. @synthesize cellBgView;
  10. @synthesize mImageView;
  11. @synthesize titleLabel;
  12. @synthesize titleLabel2;
  13. @synthesize rightImage;
  14. @synthesize lineView;
  15. @synthesize checkButton;
  16. - (void)awakeFromNib {
  17. [super awakeFromNib];
  18. // Initialization code
  19. }
  20. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  21. {
  22. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  23. if (self)
  24. {
  25. [self drawView];
  26. }
  27. return self;
  28. }
  29. - (void)drawView
  30. {
  31. cellBgView = [[UIView alloc] init];
  32. [self.contentView addSubview:cellBgView];
  33. cellBgView.backgroundColor = [UIColor whiteColor];
  34. [cellBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.left.mas_equalTo(15.f);
  36. make.top.mas_equalTo(0);
  37. make.bottom.mas_equalTo(0);
  38. make.width.mas_equalTo(SCREEN_W - 2*15.f);
  39. }];
  40. /*图片*/
  41. mImageView = [[UIImageView alloc] init];
  42. [mImageView setBackgroundColor:[UIColor clearColor]];
  43. mImageView.image = [UIImage imageNamed:@"uploadFile_image"];
  44. [cellBgView addSubview:mImageView];
  45. [mImageView setContentMode:(UIViewContentModeScaleAspectFit)];
  46. [mImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.left.mas_equalTo(15);
  48. make.width.mas_equalTo(36);
  49. make.height.mas_equalTo(36);
  50. make.centerY.equalTo(cellBgView.mas_centerY);
  51. }];
  52. /*右侧箭头*/
  53. rightImage = [[UIImageView alloc] init];
  54. [rightImage setBackgroundColor:[UIColor clearColor]];
  55. [rightImage setImage:[UIImage imageNamed:@"cell_right_access"]];
  56. [cellBgView addSubview:rightImage];
  57. [rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.width.mas_equalTo(28);
  59. make.right.mas_equalTo(-15.f);
  60. make.height.mas_equalTo(28);
  61. make.centerY.equalTo(cellBgView.mas_centerY);
  62. }];
  63. checkButton = [[UIButton alloc] init];
  64. [checkButton setImage:[UIImage imageNamed:@"upload_file_uncheck"] forState:UIControlStateNormal];
  65. [checkButton setImage:[UIImage imageNamed:@"upload_file_check"] forState:UIControlStateSelected];
  66. [cellBgView addSubview:checkButton];
  67. [checkButton mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.right.mas_equalTo(-18.f);
  69. make.centerY.equalTo(cellBgView.mas_centerY);
  70. make.width.mas_equalTo(36.f);
  71. make.height.mas_equalTo(36.f);
  72. }];
  73. [checkButton addTarget:self action:@selector(maskSwitchPressed:) forControlEvents:(UIControlEventTouchUpInside)];
  74. /**标题*/
  75. titleLabel = [[UILabel alloc] init];
  76. [cellBgView addSubview:titleLabel];
  77. titleLabel.font = [UIFont boldSystemFontOfSize:14.f];
  78. titleLabel.numberOfLines = 3;
  79. [titleLabel setTextColor:HW0A132BColor];
  80. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  81. make.left.equalTo(mImageView.mas_right).offset(5.f);
  82. make.right.equalTo(checkButton.mas_left).offset(-5.f);
  83. make.centerY.equalTo(cellBgView.mas_centerY);
  84. //make.top.mas_equalTo(15.f);
  85. }];
  86. /**副标题*/
  87. titleLabel2 = [[UILabel alloc] init];
  88. [cellBgView addSubview:titleLabel2];
  89. titleLabel2.font = [UIFont systemFontOfSize:12.f];
  90. //[titleLabel2 setTextAlignment:(NSTextAlignmentRight)];
  91. [titleLabel2 setTextColor:HW666666Color];
  92. [titleLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
  93. make.right.mas_equalTo(-53.f);
  94. make.left.mas_equalTo(titleLabel.mas_left);
  95. //make.centerY.equalTo(cellBgView.mas_centerY);
  96. make.bottom.mas_equalTo(-15);
  97. }];
  98. lineView = [[UIView alloc] init];
  99. [lineView setBackgroundColor:HW979797Color10];
  100. [cellBgView addSubview:lineView];
  101. [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.right.mas_equalTo(-15.f);
  103. make.left.mas_equalTo(15.f);
  104. make.bottom.mas_equalTo(0);
  105. make.height.mas_equalTo(1.f);
  106. }];
  107. //titleLabel2.text = @"2023/10/22";
  108. }
  109. - (void)maskSwitchPressed:(UIButton *)maskSwitch{
  110. if(_didClickSwitch){
  111. _didClickSwitch(maskSwitch.selected);
  112. }
  113. }
  114. - (void)setCurFileModel:(couldPhoneFileModel *)curFileModel
  115. {
  116. _curFileModel = curFileModel;
  117. mImageView.image = [UIImage imageNamed:@"uploadFile_image"];
  118. if([curFileModel.fileType isEqualToString:@"video"])
  119. {
  120. mImageView.image = [UIImage imageNamed:@"uploadFile_Video"];
  121. }
  122. checkButton.selected = curFileModel.isSelectType;
  123. NSString *fileName = [_curFileModel getFileNameFun];
  124. NSString*pathStr = [cachesFileManager getFilePathWithName:fileName type:DownLoadThumbnail];
  125. UIImage *curImage = [UIImage imageWithContentsOfFile:pathStr];
  126. if(curImage){
  127. mImageView.image = curImage;
  128. }
  129. //时间戳转换为日期
  130. NSString *timeStr = [[NSString alloc] initWithFormat:@"%ld",curFileModel.time];
  131. NSString *dateStr = [iTools getDateStringWithTimeStr:timeStr];
  132. NSString * totalSizeStr = nil;
  133. NSInteger totalSize_k = curFileModel.length / 1024;
  134. if(totalSize_k < 1024){
  135. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  136. }
  137. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  138. totalSizeStr = [[NSString alloc] initWithFormat:@"%.1fMB",totalSize_k/1024.0];
  139. }
  140. else{
  141. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  142. }
  143. NSString * leftStr = curFileModel.name;
  144. NSString * rightStr = [[NSString alloc] initWithFormat:@"\n%@ %@",dateStr,totalSizeStr];
  145. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@%@",leftStr,rightStr];
  146. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  147. NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length);
  148. [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#666666" alpha:1.0] range:redRange];
  149. [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
  150. // 设置行间距
  151. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  152. [paragraphStyle setLineSpacing:5]; //设置行间距
  153. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  154. titleLabel.attributedText = noteStr;
  155. }
  156. @end