photoPreViewBottomView.m 6.4 KB

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