uploadFileBottomView.m 5.8 KB

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