uploadFileBottomView.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. //
  2. // uploadFileBottomView.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2023/11/10.
  6. //
  7. #import "uploadFileBottomView.h"
  8. #import "TZAssetModel+imageData.h"
  9. @interface uploadFileBottomView ()
  10. @property(nonatomic,strong)UILabel *selectNumLabel;
  11. @property(nonatomic,strong)UILabel *uploadFileRoutelabel;
  12. @property(nonatomic,strong)UIButton *uploadButon;
  13. @end
  14. @implementation uploadFileBottomView
  15. - (id)initWithFrame:(CGRect)frame{
  16. self = [super initWithFrame:frame];
  17. [self setBackgroundColor:[UIColor whiteColor]];
  18. [self drawAnyView];
  19. return self;
  20. }
  21. - (void)drawAnyView{
  22. _selectNumLabel = [[UILabel alloc] init];
  23. _selectNumLabel.font = [UIFont boldSystemFontOfSize:16.0];
  24. _selectNumLabel.textColor = [UIColor blackColor];
  25. [self addSubview:_selectNumLabel];
  26. [_selectNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  27. make.left.mas_equalTo(15);
  28. make.top.mas_equalTo(10);
  29. make.right.mas_equalTo(-110);
  30. make.height.mas_equalTo(20);
  31. }];
  32. //设置即得标题
  33. self.indexPathsForSelectedItems = [NSMutableArray new];
  34. _uploadFileRoutelabel = [[UILabel alloc] init];
  35. _uploadFileRoutelabel.font = [UIFont systemFontOfSize:14.0];
  36. _uploadFileRoutelabel.textColor = [UIColor hwColor:@"#959799" alpha:1.0];
  37. NSString *savePath = [HWDataManager getStringWithKey:Const_photo_upload_default_path];
  38. if(!savePath||savePath.length == 0){
  39. savePath = Const_default_upload_path;
  40. }
  41. _uploadFileRoutelabel.text = [[NSString alloc] initWithFormat:@"%@: %@",NSLocalizedString(@"File_upload_path_tip",nil),savePath];
  42. [self addSubview:_uploadFileRoutelabel];
  43. [_uploadFileRoutelabel mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.left.mas_equalTo(15);
  45. make.top.mas_equalTo(_selectNumLabel.mas_bottom).offset(10);
  46. make.right.mas_equalTo(-110);
  47. make.height.mas_equalTo(20);
  48. }];
  49. //图片上传
  50. NSString* curImgUploadStr = [[NSString alloc] initWithFormat:@"%@ %@",@" ",NSLocalizedString(@"my_set_no_File_upload",nil)];
  51. // gradient
  52. CAGradientLayer *gl_But = [CAGradientLayer layer];
  53. gl_But.frame = CGRectMake(0,0,88.f,40.f);
  54. gl_But.startPoint = CGPointMake(0, 0.5);
  55. gl_But.endPoint = CGPointMake(1, 0.5);
  56. gl_But.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor];
  57. gl_But.locations = @[@(0), @(1.0f)];
  58. gl_But.cornerRadius = 8;
  59. UIButton *imageUploadBut = [[UIButton alloc] init];
  60. [imageUploadBut setImage:[UIImage imageNamed:@"upload_file_white_100"] forState:UIControlStateNormal];
  61. [imageUploadBut setTitle:curImgUploadStr forState:UIControlStateNormal];
  62. [imageUploadBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  63. imageUploadBut.titleLabel.font = [UIFont boldSystemFontOfSize:13.0];
  64. imageUploadBut.tag = 2;
  65. [imageUploadBut addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  66. [self addSubview:imageUploadBut];
  67. [imageUploadBut.layer insertSublayer:gl_But atIndex:0];
  68. [imageUploadBut bringSubviewToFront:imageUploadBut.imageView];
  69. self.uploadButon = imageUploadBut;
  70. //imageUploadBut.backgroundColor = [UIColor redColor];
  71. [imageUploadBut mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.right.mas_equalTo(-15);
  73. make.top.mas_equalTo(10);
  74. make.width.mas_equalTo(88);
  75. make.height.mas_equalTo(40);
  76. }];
  77. imageUploadBut.enabled = NO;
  78. imageUploadBut.alpha = 0.5;
  79. }
  80. #pragma mark 数据处理
  81. - (void)setIndexPathsForSelectedItems:(NSMutableArray *)indexPathsForSelectedItems
  82. {
  83. BOOL isCanUpload = YES;
  84. _indexPathsForSelectedItems = indexPathsForSelectedItems;
  85. if(!_indexPathsForSelectedItems){
  86. _indexPathsForSelectedItems = [NSMutableArray new];
  87. }
  88. //TZAssetModel imageData (以字节为单位)
  89. NSUInteger allImageData = 0;
  90. for (TZAssetModel* model in _indexPathsForSelectedItems) {
  91. // if(model.type == TZAssetModelMediaTypeVideo){
  92. // allImageData += [model.videoData length];
  93. // }
  94. // else{
  95. // allImageData += [model.imageData length];
  96. // }
  97. allImageData += model.totalBytes;
  98. }
  99. if(allImageData > self.available && self.available > 1024){
  100. isCanUpload = NO;
  101. }
  102. allImageData /= 1024;
  103. NSString *byteStr = nil;
  104. NSString *unitStr = @"KB";
  105. if(allImageData < 1024){
  106. byteStr = [[NSString alloc] initWithFormat:@"%ld",allImageData];
  107. }
  108. else if( allImageData >= 1024 && allImageData < 1024*1024){
  109. byteStr = [[NSString alloc] initWithFormat:@"%.1f",allImageData/1024.0];
  110. unitStr = @"MB";
  111. }
  112. else{
  113. byteStr = [[NSString alloc] initWithFormat:@"%.2f",allImageData/1024.0/1024.0];
  114. unitStr = @"G";
  115. }
  116. if(!_availableStorage){
  117. _availableStorage = @"--";
  118. }
  119. NSString *curStr1 = [NSString stringWithFormat:@"已选%ld项",_indexPathsForSelectedItems.count];
  120. NSString *curStr2 = [NSString stringWithFormat:@"(%@%@,%@)",byteStr,unitStr,_availableStorage];
  121. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@ %@",curStr1,curStr2];
  122. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  123. NSRange redRange = NSMakeRange([totalStr rangeOfString:curStr2].location, [totalStr rangeOfString:curStr2].length);
  124. UIColor *noteColor =[UIColor hwColor:@"#959799" alpha:1.0];
  125. if(!isCanUpload){
  126. noteColor = [UIColor redColor];
  127. }
  128. [noteStr addAttribute:NSForegroundColorAttributeName value:noteColor range:redRange];
  129. [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:redRange];
  130. // 设置行间距
  131. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  132. [paragraphStyle setLineSpacing:5]; //设置行间距
  133. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  134. _selectNumLabel.attributedText = noteStr;
  135. if(_indexPathsForSelectedItems.count > 0 && isCanUpload){
  136. self.uploadButon.enabled = YES;
  137. self.uploadButon.alpha = 1;
  138. }
  139. else
  140. {
  141. self.uploadButon.enabled = NO;
  142. self.uploadButon.alpha = 0.5;
  143. }
  144. }
  145. #pragma mark 按钮点击
  146. - (void)didClickButFun:(UIButton*)but
  147. {
  148. if(_didClickUploadFile)
  149. {
  150. _didClickUploadFile();
  151. }
  152. }
  153. @end