uploadFileBottomView.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 = @"上传路径:xxxxxxxxxxxxxxx";
  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. allImageData += [model.imageData length];
  86. }
  87. allImageData /= 1024;
  88. NSString *byteStr = nil;
  89. NSString *unitStr = @"KB";
  90. if(allImageData < 1024){
  91. byteStr = [[NSString alloc] initWithFormat:@"%ld",allImageData];
  92. }
  93. else if( allImageData >= 1024 && allImageData < 1024*1024){
  94. byteStr = [[NSString alloc] initWithFormat:@"%.1f",allImageData/1024.0];
  95. unitStr = @"MB";
  96. }
  97. else{
  98. byteStr = [[NSString alloc] initWithFormat:@"%.2f",allImageData/1024.0/1024.0];
  99. unitStr = @"G";
  100. }
  101. NSString *curStr1 = [NSString stringWithFormat:@"已选%ld项",_indexPathsForSelectedItems.count];
  102. NSString *curStr2 = [NSString stringWithFormat:@"(%@%@,可用120.00GB)",byteStr,unitStr];
  103. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@ %@",curStr1,curStr2];
  104. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  105. NSRange redRange = NSMakeRange([totalStr rangeOfString:curStr2].location, [totalStr rangeOfString:curStr2].length);
  106. [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#959799" alpha:1.0] range:redRange];
  107. [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:redRange];
  108. // 设置行间距
  109. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  110. [paragraphStyle setLineSpacing:5]; //设置行间距
  111. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  112. _selectNumLabel.attributedText = noteStr;
  113. }
  114. #pragma mark 按钮点击
  115. - (void)didClickButFun:(UIButton*)but
  116. {
  117. }
  118. @end