fileTransferPopView.m 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. //
  2. // fileTransferPopView.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2023/12/27.
  6. //
  7. #import "fileTransferPopView.h"
  8. @interface fileTransferPopView ()
  9. {
  10. UIButton *uploadButton;
  11. UIButton *downButton;
  12. }
  13. @end
  14. @implementation fileTransferPopView
  15. - (id)initWithFrame:(CGRect)frame{
  16. self = [super initWithFrame:frame];
  17. [self drawAnyView];
  18. return self;
  19. }
  20. - (void)drawAnyView{
  21. [self setBackgroundColor:[UIColor hwColor:@"#000000" alpha:0.6]];
  22. UIView *whiteBgView = [[UIView alloc] init];
  23. whiteBgView.backgroundColor = [UIColor whiteColor];
  24. whiteBgView.layer.cornerRadius = 12;
  25. [self addSubview:whiteBgView];
  26. [whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  27. make.left.mas_equalTo(0);
  28. make.right.mas_equalTo(0);
  29. make.height.mas_equalTo(237+ 10);
  30. make.bottom.mas_equalTo(10);
  31. }];
  32. UIView *tapView = [[UIView alloc] init];
  33. [self addSubview:tapView];
  34. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapUpFun:)];
  35. [tapView addGestureRecognizer:tap];
  36. [tapView mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.left.mas_equalTo(0);
  38. make.right.mas_equalTo(0);
  39. make.top.mas_equalTo(0);
  40. make.bottom.mas_equalTo(whiteBgView.mas_top);
  41. }];
  42. UIView *blackView = [[UIView alloc] init];
  43. blackView.backgroundColor = [UIColor blackColor];
  44. blackView.layer.cornerRadius = 2;
  45. [whiteBgView addSubview:blackView];
  46. [blackView mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.width.mas_equalTo(40);
  48. make.height.mas_equalTo(4);
  49. make.centerX.mas_equalTo(0);
  50. make.top.mas_equalTo(8);
  51. }];
  52. CGFloat butW = SCREEN_W - 15*2;
  53. CGFloat butH = butW * 80.0/345.0;
  54. //
  55. uploadButton = [[UIButton alloc] init];
  56. [uploadButton setBackgroundImage:[UIImage imageNamed:@"uploadFile_bg_upload"] forState:UIControlStateNormal];
  57. uploadButton.tag = 1;
  58. [uploadButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  59. [whiteBgView addSubview:uploadButton];
  60. [uploadButton mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.width.mas_equalTo(butW);
  62. make.height.mas_equalTo(butH);
  63. make.centerX.mas_equalTo(0);
  64. make.top.mas_equalTo(blackView.mas_bottom).offset(10);
  65. }];
  66. downButton = [[UIButton alloc] init];
  67. downButton.tag = 2;
  68. [downButton setBackgroundImage:[UIImage imageNamed:@"uploadFile_bg_downLoad"] forState:UIControlStateNormal];
  69. [downButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  70. [whiteBgView addSubview:downButton];
  71. [downButton mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.width.mas_equalTo(butW);
  73. make.height.mas_equalTo(butH);
  74. make.centerX.mas_equalTo(0);
  75. make.top.mas_equalTo(uploadButton.mas_bottom).offset(15);
  76. }];
  77. }
  78. - (void)setFileTransferType:(NSInteger)fileTransferType
  79. {
  80. _fileTransferType = fileTransferType;
  81. NSString *uploadTitle = NSLocalizedString(@"File_upload_type_image",nil);
  82. NSString *uploadTip = NSLocalizedString(@"File_upload_type_tip",nil);
  83. NSString *downloadTitle = NSLocalizedString(@"File_down_type_image",nil);
  84. NSString *downloadTip = NSLocalizedString(@"File_down_type_tip",nil);
  85. if(fileTransferType == 2)
  86. {
  87. uploadTitle = NSLocalizedString(@"File_upload_type_video",nil);
  88. downloadTitle = NSLocalizedString(@"File_down_type_video",nil);
  89. }
  90. UILabel *uploadLabel = [[UILabel alloc] init];
  91. uploadLabel.textColor = [UIColor whiteColor];
  92. uploadLabel.font = [UIFont boldSystemFontOfSize:18.0];
  93. uploadLabel.numberOfLines = 0;
  94. [uploadButton addSubview:uploadLabel];
  95. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@\n%@",uploadTitle,uploadTip];
  96. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  97. NSRange redRange = NSMakeRange([totalStr rangeOfString:uploadTip].location, [totalStr rangeOfString:uploadTip].length);
  98. [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#FFFFFF" alpha:0.8] range:redRange];
  99. [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:redRange];
  100. // 设置行间距
  101. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  102. [paragraphStyle setLineSpacing:5]; //设置行间距
  103. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  104. uploadLabel.attributedText = noteStr;
  105. [uploadLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  106. make.left.mas_equalTo(15);
  107. make.right.mas_equalTo(-15);
  108. make.bottom.mas_equalTo(0);
  109. make.top.mas_equalTo(0);
  110. }];
  111. UILabel *downloadLabel = [[UILabel alloc] init];
  112. downloadLabel.textColor = [UIColor whiteColor];
  113. downloadLabel.font = [UIFont boldSystemFontOfSize:18.0];
  114. downloadLabel.numberOfLines = 0;
  115. [downButton addSubview:downloadLabel];
  116. NSString *downTotalStr = [[NSString alloc] initWithFormat:@"%@\n%@",downloadTitle,downloadTip];
  117. NSMutableAttributedString *downNoteStr = [[NSMutableAttributedString alloc] initWithString:downTotalStr];
  118. NSRange downredRange = NSMakeRange([downTotalStr rangeOfString:downloadTip].location, [downTotalStr rangeOfString:downloadTip].length);
  119. [downNoteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#FFFFFF" alpha:0.8] range:downredRange];
  120. [downNoteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:downredRange];
  121. // 设置行间距
  122. // NSMutableParagraphStyle *paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
  123. // [paragraphStyle1 setLineSpacing:5]; //设置行间距
  124. [downNoteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [downTotalStr length])];
  125. downloadLabel.attributedText = downNoteStr;
  126. [downloadLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  127. make.left.mas_equalTo(15);
  128. make.right.mas_equalTo(-15);
  129. make.bottom.mas_equalTo(0);
  130. make.top.mas_equalTo(0);
  131. }];
  132. }
  133. - (void)tapUpFun:(UITapGestureRecognizer*)tap
  134. {
  135. [self removeFromSuperview];
  136. }
  137. - (void)didClickButtonFun:(UIButton*)button
  138. {
  139. [self tapUpFun:nil];
  140. NSInteger tag = button.tag;
  141. NSInteger didTag = -1;
  142. if(_fileTransferType == 1){
  143. if(tag == 1){
  144. didTag = 11;
  145. }
  146. else if(tag == 2){
  147. didTag = 12;
  148. }
  149. }
  150. else if(_fileTransferType == 2){
  151. if(tag == 1){
  152. didTag = 21;
  153. }
  154. else if(tag == 2){
  155. didTag = 22;
  156. }
  157. }
  158. if(didTag){
  159. if(_didClickBut)
  160. {
  161. _didClickBut(didTag);
  162. }
  163. }
  164. }
  165. @end