NASMySpaceView.m 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. //
  2. // NASMySpaceView.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/6/19.
  6. //
  7. #import "NASMySpaceView.h"
  8. @interface NASMySpaceView ()
  9. @property(nonatomic,strong) UILabel*titleLabel;
  10. //渐变色进度条
  11. @property(nonatomic,strong) UIView *progressBgView;
  12. @property(nonatomic,strong) UIView *progressSelectView;
  13. @property(nonatomic,strong) CAGradientLayer *glayer;
  14. @end
  15. @implementation NASMySpaceView
  16. - (id)initWithFrame:(CGRect)frame{
  17. self = [super initWithFrame:frame];
  18. //self.backgroundColor = [UIColor clearColor];
  19. [self drawAnyView];
  20. return self;
  21. }
  22. -(void)drawAnyView
  23. {
  24. UIView *whiteBgView = [[UIView alloc] init];
  25. whiteBgView.backgroundColor = [UIColor whiteColor];
  26. [self addSubview:whiteBgView];
  27. whiteBgView.layer.cornerRadius = 12;
  28. whiteBgView.layer.masksToBounds = YES;
  29. [whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.top.mas_equalTo(0);
  31. make.left.mas_equalTo(16);
  32. make.right.mas_equalTo(-16);
  33. make.bottom.mas_equalTo(0);
  34. }];
  35. _titleLabel = [[UILabel alloc] init];
  36. _titleLabel.font = [UIFont systemFontOfSize:12.0];
  37. _titleLabel.textColor = [UIColor hwColor:@"#818CA2"];
  38. [whiteBgView addSubview:_titleLabel];
  39. [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.top.mas_equalTo(16);
  41. make.left.mas_equalTo(16);
  42. make.right.mas_equalTo(-24-12-10);
  43. make.height.mas_equalTo(20);
  44. }];
  45. [self setTitleLabelTextFunBy:@"--GB/--GB"];
  46. //添加按钮 后面做个大按钮响应
  47. UIButton *rightButton = [[UIButton alloc] init];
  48. [rightButton setBackgroundImage:[UIImage imageNamed:@"common_right_arrow"] forState:UIControlStateNormal];
  49. // rightButton.tag = 1;
  50. // [rightButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  51. [whiteBgView addSubview:rightButton];
  52. [rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.top.mas_equalTo(16);
  54. make.right.mas_equalTo(-12);
  55. make.width.mas_equalTo(24);
  56. make.height.mas_equalTo(24);
  57. }];
  58. _progressBgView = [[UIView alloc] init];
  59. _progressBgView.backgroundColor = [UIColor hwColor:@"#E7EFFA" alpha:1.0];
  60. _progressBgView.layer.cornerRadius = 5;
  61. _progressBgView.layer.masksToBounds = YES;
  62. [whiteBgView addSubview:_progressBgView];
  63. [_progressBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.left.mas_equalTo(16);
  65. make.right.mas_equalTo(-16);
  66. make.height.mas_equalTo(10);
  67. make.top.equalTo(_titleLabel.mas_bottom).offset(12);
  68. }];
  69. _progressSelectView = [[UIView alloc] init];
  70. _progressSelectView.layer.cornerRadius = 5;
  71. _progressSelectView.layer.masksToBounds = YES;
  72. [_progressBgView addSubview:_progressSelectView];
  73. // gradient
  74. _glayer = [CAGradientLayer layer];
  75. _glayer.startPoint = CGPointMake(0, 0.5);
  76. _glayer.endPoint = CGPointMake(0.97, 0.5);
  77. _glayer.colors = @[(__bridge id)[UIColor hwColor:@"#0CDEFD" alpha:1.0].CGColor, (__bridge id)[UIColor hwColor:@"#058DFB" alpha:1.0].CGColor];
  78. _glayer.locations = @[@(0), @(1.0f)];
  79. [_progressSelectView.layer addSublayer:_glayer];
  80. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  81. // [self setProgressFun];
  82. // });
  83. //大按钮响应
  84. UIButton *bigRightButton = [[UIButton alloc] init];
  85. bigRightButton.tag = 1;
  86. [bigRightButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  87. [whiteBgView addSubview:bigRightButton];
  88. //bigRightButton.backgroundColor= [UIColor redColor];
  89. [bigRightButton mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.top.mas_equalTo(16);
  91. make.left.mas_equalTo(0);
  92. make.right.mas_equalTo(0);
  93. make.bottom.equalTo(_progressSelectView.mas_bottom).offset(0);
  94. }];
  95. NSArray *titleArr = @[NSLocalizedString(@"nas_app_title",nil),
  96. NSLocalizedString(@"my_set_no_image_upload",nil),
  97. NSLocalizedString(@"my_set_no_video_upload",nil),
  98. NSLocalizedString(@"my_set_no_music",nil),
  99. NSLocalizedString(@"my_set_no_file",nil)];
  100. NSArray *imageArr = @[@"nas_app_icon",
  101. @"nas_picture_icon",
  102. @"nas_video_icon",
  103. @"nas_audio_icon",
  104. @"nas_file_icon"];
  105. CGFloat butTopY = 74.0;
  106. CGFloat butWidth = 42.0;
  107. CGFloat butHeight = 42.0 +20 +5;
  108. CGFloat leftSpace = 18.0;
  109. CGFloat butSpace = (SCREEN_W -16*2 -leftSpace*2 - butWidth*titleArr.count)/4.0;
  110. for (int i=0; i<titleArr.count; i++) {
  111. UIImageView *imageV = [[UIImageView alloc] init];
  112. imageV.image = [UIImage imageNamed:imageArr[i]];
  113. imageV.backgroundColor = [UIColor hwColor:@"#F5F6F7"];
  114. imageV.layer.cornerRadius = 10;
  115. imageV.layer.masksToBounds = YES;
  116. [whiteBgView addSubview:imageV];
  117. [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
  118. make.left.mas_equalTo(leftSpace + (butWidth+butSpace)*i);
  119. make.width.mas_equalTo(butWidth);
  120. make.height.mas_equalTo(butWidth);
  121. make.top.mas_equalTo(butTopY);
  122. }];
  123. UILabel *textLabel = [[UILabel alloc] init];
  124. textLabel.textAlignment = NSTextAlignmentCenter;
  125. textLabel.font = [UIFont systemFontOfSize:14.0];
  126. textLabel.textColor = [UIColor hwColor:@"#0A132B"];
  127. textLabel.text = titleArr[i];
  128. [whiteBgView addSubview:textLabel];
  129. [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  130. make.left.mas_equalTo(leftSpace + (butWidth+butSpace)*i);
  131. make.width.mas_equalTo(butWidth);
  132. make.height.mas_equalTo(20);
  133. make.top.equalTo(imageV.mas_bottom).offset(5);
  134. }];
  135. UIButton *but = [[UIButton alloc] init];
  136. but.tag = 10+i-1;//新加了一个在前面
  137. [but addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  138. [whiteBgView addSubview:but];
  139. [but mas_makeConstraints:^(MASConstraintMaker *make) {
  140. make.left.mas_equalTo(leftSpace + (butWidth+butSpace)*i);
  141. make.width.mas_equalTo(butWidth);
  142. make.height.mas_equalTo(butHeight);
  143. make.top.mas_equalTo(butTopY);
  144. }];
  145. }
  146. }
  147. - (void)setTitleLabelTextFunBy:(NSString*)datsStr
  148. {
  149. NSString*title1 = NSLocalizedString(@"NAS_mySpace_title",nil);
  150. NSString*title2 = NSLocalizedString(@"NAS_used_Space",nil);
  151. NSString*title3 = datsStr;
  152. NSString *fullTitle = [[NSString alloc] initWithFormat:@"%@ %@%@",title1,title2,title3];
  153. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:fullTitle];
  154. NSRange redRange = NSMakeRange([fullTitle rangeOfString:title1].location, [fullTitle rangeOfString:title1].length);
  155. UIColor *noteColor =[UIColor hwColor:@"#262626" alpha:1.0];
  156. [attrStr addAttribute:NSForegroundColorAttributeName value:noteColor range:redRange];
  157. [attrStr addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:16.0] range:redRange];
  158. _titleLabel.attributedText = attrStr;
  159. }
  160. - (void)setProgressFun
  161. {
  162. if(!ksharedAppDelegate.cloudPhoneExtraFileListMod.data){
  163. return;
  164. }
  165. long allExtraAvableSize = 0;
  166. long allExtraTotalSize = 0;
  167. for (cloudPhoneExtraFileModel*model in ksharedAppDelegate.cloudPhoneExtraFileListMod.data) {
  168. allExtraAvableSize += model.extraAvableSize;
  169. allExtraTotalSize += model.extraTotalSize;
  170. }
  171. if(allExtraTotalSize == 0){
  172. return;
  173. }
  174. CGFloat rate = (allExtraTotalSize - allExtraAvableSize)/(allExtraTotalSize*1.0);
  175. CGRect frame = _progressBgView.bounds;
  176. frame.size.width = frame.size.width * rate;
  177. if (!isnan(frame.size.width))
  178. {
  179. _progressSelectView.frame = frame;
  180. _glayer.frame = frame;
  181. }
  182. // 计算 大小
  183. CGFloat extraAvableSizeF = allExtraAvableSize / 1024.0 /1024.0/1024.0;
  184. CGFloat extraTotalSizeF = allExtraTotalSize / 1024.0 /1024.0/1024.0;
  185. NSString *dataStr = [[NSString alloc] initWithFormat:@"%.2fGB/%.2fGB",(extraTotalSizeF - extraAvableSizeF),extraTotalSizeF];
  186. [self setTitleLabelTextFunBy:dataStr];
  187. }
  188. #pragma mark 按钮事件
  189. - (void)didClickButtonFun:(UIButton*)but
  190. {
  191. NSInteger tag = but.tag;
  192. HLog(@"%ld",tag);
  193. if(_didClickButtonFun){
  194. _didClickButtonFun(tag);
  195. }
  196. }
  197. @end