123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- //
- // NASMySpaceView.m
- // 双子星云手机
- //
- // Created by xd h on 2024/6/19.
- //
- #import "NASMySpaceView.h"
- @interface NASMySpaceView ()
- @property(nonatomic,strong) UILabel*titleLabel;
- //渐变色进度条
- @property(nonatomic,strong) UIView *progressBgView;
- @property(nonatomic,strong) UIView *progressSelectView;
- @property(nonatomic,strong) CAGradientLayer *glayer;
- @end
- @implementation NASMySpaceView
- - (id)initWithFrame:(CGRect)frame{
- self = [super initWithFrame:frame];
-
- //self.backgroundColor = [UIColor clearColor];
- [self drawAnyView];
-
- return self;
- }
- -(void)drawAnyView
- {
- UIView *whiteBgView = [[UIView alloc] init];
- whiteBgView.backgroundColor = [UIColor whiteColor];
- [self addSubview:whiteBgView];
- whiteBgView.layer.cornerRadius = 12;
- whiteBgView.layer.masksToBounds = YES;
-
- [whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(0);
- make.left.mas_equalTo(16);
- make.right.mas_equalTo(-16);
- make.bottom.mas_equalTo(0);
- }];
-
- _titleLabel = [[UILabel alloc] init];
- _titleLabel.font = [UIFont systemFontOfSize:12.0];
- _titleLabel.textColor = [UIColor hwColor:@"#818CA2"];
- [whiteBgView addSubview:_titleLabel];
-
- [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(16);
- make.left.mas_equalTo(16);
- make.right.mas_equalTo(-24-12-10);
- make.height.mas_equalTo(20);
- }];
-
- [self setTitleLabelTextFunBy:@"--GB/--GB"];
-
- //添加按钮 后面做个大按钮响应
- UIButton *rightButton = [[UIButton alloc] init];
- [rightButton setBackgroundImage:[UIImage imageNamed:@"common_right_arrow"] forState:UIControlStateNormal];
- // rightButton.tag = 1;
- // [rightButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
- [whiteBgView addSubview:rightButton];
-
- [rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(16);
- make.right.mas_equalTo(-12);
- make.width.mas_equalTo(24);
- make.height.mas_equalTo(24);
- }];
-
- _progressBgView = [[UIView alloc] init];
- _progressBgView.backgroundColor = [UIColor hwColor:@"#E7EFFA" alpha:1.0];
- _progressBgView.layer.cornerRadius = 5;
- _progressBgView.layer.masksToBounds = YES;
- [whiteBgView addSubview:_progressBgView];
-
- [_progressBgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(16);
- make.right.mas_equalTo(-16);
- make.height.mas_equalTo(10);
- make.top.equalTo(_titleLabel.mas_bottom).offset(12);
- }];
-
- _progressSelectView = [[UIView alloc] init];
- _progressSelectView.layer.cornerRadius = 5;
- _progressSelectView.layer.masksToBounds = YES;
- [_progressBgView addSubview:_progressSelectView];
-
- // gradient
- _glayer = [CAGradientLayer layer];
- _glayer.startPoint = CGPointMake(0, 0.5);
- _glayer.endPoint = CGPointMake(0.97, 0.5);
- _glayer.colors = @[(__bridge id)[UIColor hwColor:@"#0CDEFD" alpha:1.0].CGColor, (__bridge id)[UIColor hwColor:@"#058DFB" alpha:1.0].CGColor];
- _glayer.locations = @[@(0), @(1.0f)];
- [_progressSelectView.layer addSublayer:_glayer];
-
- // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- // [self setProgressFun];
- // });
-
- //大按钮响应
- UIButton *bigRightButton = [[UIButton alloc] init];
- bigRightButton.tag = 1;
- [bigRightButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
- [whiteBgView addSubview:bigRightButton];
- //bigRightButton.backgroundColor= [UIColor redColor];
-
- [bigRightButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(16);
- make.left.mas_equalTo(0);
- make.right.mas_equalTo(0);
- make.bottom.equalTo(_progressSelectView.mas_bottom).offset(0);
- }];
-
-
- NSArray *titleArr = @[NSLocalizedString(@"my_set_no_image_upload",nil),
- NSLocalizedString(@"my_set_no_video_upload",nil),
- NSLocalizedString(@"my_set_no_music",nil),
- NSLocalizedString(@"my_set_no_file",nil)];
-
- NSArray *imageArr = @[@"nas_picture_icon",
- @"nas_video_icon",
- @"nas_audio_icon",
- @"nas_file_icon"];
-
- CGFloat butTopY = 74.0;
- CGFloat butWidth = 52.0;
- CGFloat butHeight = 52.0 +20 +5;
- CGFloat leftSpace = 20.0;
- CGFloat butSpace = (SCREEN_W -16*2 -leftSpace*2 - butWidth*titleArr.count)/3.0;
-
-
- for (int i=0; i<titleArr.count; i++) {
- UIImageView *imageV = [[UIImageView alloc] init];
- imageV.image = [UIImage imageNamed:imageArr[i]];
- imageV.backgroundColor = [UIColor hwColor:@"#F5F6F7"];
- imageV.layer.cornerRadius = 10;
- imageV.layer.masksToBounds = YES;
- [whiteBgView addSubview:imageV];
-
- [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(leftSpace + (butWidth+butSpace)*i);
- make.width.mas_equalTo(butWidth);
- make.height.mas_equalTo(butWidth);
- make.top.mas_equalTo(butTopY);
- }];
-
- UILabel *textLabel = [[UILabel alloc] init];
- textLabel.textAlignment = NSTextAlignmentCenter;
- textLabel.font = [UIFont systemFontOfSize:14.0];
- textLabel.textColor = [UIColor hwColor:@"#0A132B"];
- textLabel.text = titleArr[i];
- [whiteBgView addSubview:textLabel];
-
- [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(leftSpace + (butWidth+butSpace)*i);
- make.width.mas_equalTo(butWidth);
- make.height.mas_equalTo(20);
- make.top.equalTo(imageV.mas_bottom).offset(5);
- }];
-
- UIButton *but = [[UIButton alloc] init];
- but.tag = 10+i;
- [but addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
- [whiteBgView addSubview:but];
-
- [but mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(leftSpace + (butWidth+butSpace)*i);
- make.width.mas_equalTo(butWidth);
- make.height.mas_equalTo(butHeight);
- make.top.mas_equalTo(butTopY);
- }];
- }
-
- }
- - (void)setTitleLabelTextFunBy:(NSString*)datsStr
- {
- NSString*title1 = NSLocalizedString(@"NAS_mySpace_title",nil);
- NSString*title2 = NSLocalizedString(@"NAS_used_Space",nil);
- NSString*title3 = datsStr;
-
- NSString *fullTitle = [[NSString alloc] initWithFormat:@"%@ %@%@",title1,title2,title3];
-
- NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:fullTitle];
- NSRange redRange = NSMakeRange([fullTitle rangeOfString:title1].location, [fullTitle rangeOfString:title1].length);
- UIColor *noteColor =[UIColor hwColor:@"#262626" alpha:1.0];
- [attrStr addAttribute:NSForegroundColorAttributeName value:noteColor range:redRange];
- [attrStr addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:16.0] range:redRange];
-
- _titleLabel.attributedText = attrStr;
- }
- - (void)setProgressFun
- {
- if(!ksharedAppDelegate.cloudPhoneExtraFileListMod.data){
- return;
- }
-
- long allExtraAvableSize = 0;
- long allExtraTotalSize = 0;
- for (cloudPhoneExtraFileModel*model in ksharedAppDelegate.cloudPhoneExtraFileListMod.data) {
- allExtraAvableSize += model.extraAvableSize;
- allExtraTotalSize += model.extraTotalSize;
- }
-
- if(allExtraTotalSize == 0){
- return;
- }
-
- CGFloat rate = (allExtraTotalSize - allExtraAvableSize)/(allExtraTotalSize*1.0);
-
- CGRect frame = _progressBgView.bounds;
- frame.size.width = frame.size.width * rate;
-
- if (!isnan(frame.size.width))
- {
- _progressSelectView.frame = frame;
- _glayer.frame = frame;
- }
-
-
- // 计算 大小
- CGFloat extraAvableSizeF = allExtraAvableSize / 1024.0 /1024.0/1024.0;
- CGFloat extraTotalSizeF = allExtraTotalSize / 1024.0 /1024.0/1024.0;
-
- NSString *dataStr = [[NSString alloc] initWithFormat:@"%.2fGB/%.2fGB",(extraTotalSizeF - extraAvableSizeF),extraTotalSizeF];
- [self setTitleLabelTextFunBy:dataStr];
- }
- #pragma mark 按钮事件
- - (void)didClickButtonFun:(UIButton*)but
- {
- NSInteger tag = but.tag;
- HLog(@"%ld",tag);
-
- if(_didClickButtonFun){
- _didClickButtonFun(tag);
- }
- }
- @end
|