NASMySpaceView.m 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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(@"my_set_no_image_upload",nil),
  96. NSLocalizedString(@"my_set_no_video_upload",nil),
  97. NSLocalizedString(@"my_set_no_music",nil),
  98. NSLocalizedString(@"my_set_no_file",nil)];
  99. NSArray *imageArr = @[@"nas_picture_icon",
  100. @"nas_video_icon",
  101. @"nas_audio_icon",
  102. @"nas_file_icon"];
  103. CGFloat butTopY = 74.0;
  104. CGFloat butWidth = 52.0;
  105. CGFloat butHeight = 52.0 +20 +5;
  106. CGFloat leftSpace = 20.0;
  107. CGFloat butSpace = (SCREEN_W -16*2 -leftSpace*2 - butWidth*titleArr.count)/3.0;
  108. for (int i=0; i<titleArr.count; i++) {
  109. UIImageView *imageV = [[UIImageView alloc] init];
  110. imageV.image = [UIImage imageNamed:imageArr[i]];
  111. imageV.backgroundColor = [UIColor hwColor:@"#F5F6F7"];
  112. imageV.layer.cornerRadius = 10;
  113. imageV.layer.masksToBounds = YES;
  114. [whiteBgView addSubview:imageV];
  115. [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
  116. make.left.mas_equalTo(leftSpace + (butWidth+butSpace)*i);
  117. make.width.mas_equalTo(butWidth);
  118. make.height.mas_equalTo(butWidth);
  119. make.top.mas_equalTo(butTopY);
  120. }];
  121. UILabel *textLabel = [[UILabel alloc] init];
  122. textLabel.textAlignment = NSTextAlignmentCenter;
  123. textLabel.font = [UIFont systemFontOfSize:14.0];
  124. textLabel.textColor = [UIColor hwColor:@"#0A132B"];
  125. textLabel.text = titleArr[i];
  126. [whiteBgView addSubview:textLabel];
  127. [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  128. make.left.mas_equalTo(leftSpace + (butWidth+butSpace)*i);
  129. make.width.mas_equalTo(butWidth);
  130. make.height.mas_equalTo(20);
  131. make.top.equalTo(imageV.mas_bottom).offset(5);
  132. }];
  133. UIButton *but = [[UIButton alloc] init];
  134. but.tag = 10+i;
  135. [but addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  136. [whiteBgView addSubview:but];
  137. [but mas_makeConstraints:^(MASConstraintMaker *make) {
  138. make.left.mas_equalTo(leftSpace + (butWidth+butSpace)*i);
  139. make.width.mas_equalTo(butWidth);
  140. make.height.mas_equalTo(butHeight);
  141. make.top.mas_equalTo(butTopY);
  142. }];
  143. }
  144. }
  145. - (void)setTitleLabelTextFunBy:(NSString*)datsStr
  146. {
  147. NSString*title1 = NSLocalizedString(@"NAS_mySpace_title",nil);
  148. NSString*title2 = NSLocalizedString(@"NAS_used_Space",nil);
  149. NSString*title3 = datsStr;
  150. NSString *fullTitle = [[NSString alloc] initWithFormat:@"%@ %@%@",title1,title2,title3];
  151. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:fullTitle];
  152. NSRange redRange = NSMakeRange([fullTitle rangeOfString:title1].location, [fullTitle rangeOfString:title1].length);
  153. UIColor *noteColor =[UIColor hwColor:@"#262626" alpha:1.0];
  154. [attrStr addAttribute:NSForegroundColorAttributeName value:noteColor range:redRange];
  155. [attrStr addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:16.0] range:redRange];
  156. _titleLabel.attributedText = attrStr;
  157. }
  158. - (void)setProgressFun
  159. {
  160. if(!ksharedAppDelegate.cloudPhoneExtraFileListMod.data){
  161. return;
  162. }
  163. long allExtraAvableSize = 0;
  164. long allExtraTotalSize = 0;
  165. for (cloudPhoneExtraFileModel*model in ksharedAppDelegate.cloudPhoneExtraFileListMod.data) {
  166. allExtraAvableSize += model.extraAvableSize;
  167. allExtraTotalSize += model.extraTotalSize;
  168. }
  169. if(allExtraTotalSize == 0){
  170. return;
  171. }
  172. CGFloat rate = (allExtraTotalSize - allExtraAvableSize)/(allExtraTotalSize*1.0);
  173. CGRect frame = _progressBgView.bounds;
  174. frame.size.width = frame.size.width * rate;
  175. if (!isnan(frame.size.width))
  176. {
  177. _progressSelectView.frame = frame;
  178. _glayer.frame = frame;
  179. }
  180. // 计算 大小
  181. CGFloat extraAvableSizeF = allExtraAvableSize / 1024.0 /1024.0/1024.0;
  182. CGFloat extraTotalSizeF = allExtraTotalSize / 1024.0 /1024.0/1024.0;
  183. NSString *dataStr = [[NSString alloc] initWithFormat:@"%.2fGB/%.2fGB",(extraTotalSizeF - extraAvableSizeF),extraTotalSizeF];
  184. [self setTitleLabelTextFunBy:dataStr];
  185. }
  186. #pragma mark 按钮事件
  187. - (void)didClickButtonFun:(UIButton*)but
  188. {
  189. NSInteger tag = but.tag;
  190. HLog(@"%ld",tag);
  191. if(_didClickButtonFun){
  192. _didClickButtonFun(tag);
  193. }
  194. }
  195. @end