imageVersionRenewTipView.m 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. //
  2. // imageVersionRenewTipView.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2023/12/21.
  6. //
  7. #import "imageVersionRenewTipView.h"
  8. @interface imageVersionRenewTipView ()
  9. @property (nonatomic,strong) UIView* whiteBgView;
  10. @property (nonatomic,strong) UIButton *updateNowBut;
  11. @property (nonatomic,strong) CAGradientLayer *gradientLayer;
  12. @property (nonatomic,strong) UILabel *tip1Lab;
  13. @end
  14. @implementation imageVersionRenewTipView
  15. - (id)initWithFrame:(CGRect)frame{
  16. self = [super initWithFrame:frame];
  17. self.backgroundColor = [UIColor hwColor:@"000000" alpha:0.6];
  18. [self drawAnyView];
  19. return self;
  20. }
  21. - (void)drawAnyView{
  22. _whiteBgView = [UIView new];
  23. _whiteBgView.layer.cornerRadius = 8;
  24. _whiteBgView.backgroundColor = [UIColor whiteColor];
  25. [self addSubview:_whiteBgView];
  26. [_whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  27. make.height.mas_equalTo(369.f);
  28. make.width.mas_equalTo(323.f*AUTOSCALE);
  29. make.centerY.mas_equalTo(-40.f);
  30. make.centerX.mas_equalTo(0.f);
  31. }];
  32. UIImageView *topImage = [[UIImageView alloc] init];
  33. topImage.image = [UIImage imageNamed:@"imageVersionTipBg"];
  34. [_whiteBgView addSubview:topImage];
  35. [topImage mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.height.mas_equalTo(244*AUTOSCALE);
  37. make.width.mas_equalTo(323.f*AUTOSCALE);
  38. make.left.mas_equalTo(0.f);
  39. make.top.mas_equalTo(-40.f);
  40. }];
  41. NSString *curTitleStr = NSLocalizedString(@"image_version_pop_title",nil);
  42. UILabel *titleLab = [[UILabel alloc] init];
  43. titleLab.text = curTitleStr;
  44. titleLab.numberOfLines = 0;
  45. titleLab.textColor = [UIColor blackColor];
  46. titleLab.font = [UIFont boldSystemFontOfSize:33.0];
  47. [topImage addSubview:titleLab];
  48. [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.height.mas_equalTo(60);
  50. make.right.mas_equalTo(0.f);
  51. make.left.mas_equalTo(25.f);
  52. make.top.mas_equalTo(42.f);
  53. }];
  54. NSString *curTip1Str = NSLocalizedString(@"image_version_pop_144_tip1",nil);
  55. NSString *curTipRedStr = NSLocalizedString(@"image_version_pop_144_tip1_2",nil);
  56. _tip1Lab = [[UILabel alloc] init];
  57. //_tip1Lab.text = curTip1Str;
  58. _tip1Lab.numberOfLines = 0;
  59. //_tip1Lab.textAlignment = NSTextAlignmentCenter;
  60. _tip1Lab.textColor = [UIColor hwColor:@"#333333" alpha:1.0];
  61. _tip1Lab.font = [UIFont systemFontOfSize:15.0];
  62. [_whiteBgView addSubview:_tip1Lab];
  63. //_tip1Lab.backgroundColor = [UIColor greenColor];
  64. NSString *fullTitle = [[NSString alloc] initWithFormat:@"%@%@",curTip1Str,curTipRedStr];
  65. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:fullTitle];
  66. NSRange rightRange = NSMakeRange([fullTitle rangeOfString:curTipRedStr].location, curTipRedStr.length);
  67. UIColor *rightColor =[UIColor hwColor:@"#FF2828" alpha:1.0];
  68. [attrStr addAttribute:NSForegroundColorAttributeName value:rightColor range:rightRange];
  69. // 设置行间距
  70. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  71. [paragraphStyle setLineSpacing:5]; //设置行间距
  72. [attrStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [fullTitle length])];
  73. _tip1Lab.attributedText = attrStr;
  74. [_tip1Lab mas_makeConstraints:^(MASConstraintMaker *make) {
  75. //make.height.mas_equalTo(curHeight);
  76. make.right.mas_equalTo(-32.0);
  77. make.left.mas_equalTo(32.0);
  78. make.top.mas_equalTo(150);
  79. }];
  80. _updateNowBut = [[UIButton alloc] init];
  81. [_updateNowBut setTitle:NSLocalizedString(@"image_version_Update_Now",nil) forState:UIControlStateNormal];
  82. //_updateNowBut.layer.cornerRadius = 8;
  83. //_updateNowBut.layer.masksToBounds = YES;
  84. [_updateNowBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  85. [_updateNowBut addTarget:self action:@selector(didClickUpdateFun) forControlEvents:UIControlEventTouchUpInside];
  86. [_whiteBgView addSubview:_updateNowBut];
  87. _gradientLayer = [CAGradientLayer layer];
  88. _gradientLayer.frame = CGRectMake(0, 0, 268, 40);
  89. _gradientLayer.colors = @[(__bridge NSString *)[UIColor hwColor:@"#0CDEFD" alpha:1.0].CGColor, (__bridge NSString *)[UIColor hwColor:@"#058DFB" alpha:1.0].CGColor];
  90. _gradientLayer.locations = @[@(0), @(1.0f)];
  91. _gradientLayer.startPoint = CGPointMake(0, 0.5);
  92. _gradientLayer.endPoint = CGPointMake(0.97, 0.5);
  93. _gradientLayer.cornerRadius = 8;
  94. [_updateNowBut.layer addSublayer:_gradientLayer];
  95. _updateNowBut.layer.shadowColor = [UIColor hwColor:@"#058DFB"].CGColor;
  96. // 设置阴影透明度(0.0到1.0)
  97. _updateNowBut.layer.shadowOpacity = 0.5;
  98. // 设置阴影偏移量(x, y)
  99. _updateNowBut.layer.shadowOffset = CGSizeMake(0, 3);
  100. // 设置阴影模糊半径
  101. _updateNowBut.layer.shadowRadius = 5.0;
  102. // 为了使阴影在按钮外部可见,需要设置masksToBounds为NO
  103. // 注意:如果父视图设置了masksToBounds为YES,那么阴影可能仍然不可见
  104. _updateNowBut.layer.masksToBounds = NO;
  105. [_updateNowBut mas_makeConstraints:^(MASConstraintMaker *make) {
  106. make.height.mas_equalTo(40.f);
  107. make.width.mas_equalTo(268.f);
  108. make.centerX.mas_equalTo(0.f);
  109. make.bottom.mas_equalTo(-30);
  110. }];
  111. // UIButton *colseBut = [[UIButton alloc] init];
  112. // [colseBut setImage:[UIImage imageNamed:@"common_del_white"] forState:UIControlStateNormal];
  113. // [colseBut addTarget:self action:@selector(colseFun) forControlEvents:UIControlEventTouchUpInside];
  114. // [self addSubview:colseBut];
  115. //
  116. // [colseBut mas_makeConstraints:^(MASConstraintMaker *make) {
  117. // make.height.mas_equalTo(48);
  118. // make.width.mas_equalTo(48.f);
  119. // make.centerX.mas_equalTo(0.f);
  120. // make.top.mas_equalTo(_whiteBgView.mas_bottom).offset(30);
  121. // }];
  122. }
  123. - (void)didClickUpdateFun
  124. {
  125. if(_didClickUpdateNowFun){
  126. _didClickUpdateNowFun();
  127. }
  128. }
  129. - (void)colseFun
  130. {
  131. NSString *datestr = [iTools getNowDateString];
  132. [HWDataManager setObjectWithKey:Const_did_show_image_version_date value:datestr];
  133. [self removeFromSuperview];
  134. if(_didClickCloseFun){
  135. _didClickCloseFun();
  136. }
  137. }
  138. #pragma mark ota 镜像升级变化
  139. //状态 -1=没有更新 0=下载中 1=下载完成 2=点击升级 3=宿主机代理导入容器镜像:进度条展示20% 4=导入容器镜像完成:进度条展示50% 5=宿主机代理创建容器镜像:进度条展示80% 6=容器镜像创建完成:进度条展示100%
  140. - (void)setStatus:(NSInteger)status{
  141. if(status <= 1){
  142. //默认是1的UI 不用处理
  143. return;
  144. }
  145. [_whiteBgView mas_updateConstraints:^(MASConstraintMaker *make) {
  146. make.height.mas_equalTo(470.f);
  147. }];
  148. _updateNowBut.userInteractionEnabled = NO;
  149. _updateNowBut.layer.masksToBounds = YES;
  150. _updateNowBut.layer.shadowColor = [UIColor clearColor].CGColor;
  151. _updateNowBut.backgroundColor = [UIColor hwColor:@"#DADBDC"];
  152. _updateNowBut.layer.cornerRadius = 8;
  153. CGFloat curProgress = 0.0;
  154. if(status == 2){
  155. curProgress = 0.0;
  156. }
  157. else if(status == 3){
  158. curProgress = 0.2;
  159. }
  160. else if(status == 4){
  161. curProgress = 0.5;
  162. }
  163. else if(status == 5){
  164. curProgress = 0.8;
  165. }
  166. else //if(status == 6)
  167. {
  168. curProgress = 1.0;
  169. }
  170. _gradientLayer.frame = CGRectMake(0, 0, 268*curProgress, 40);
  171. NSString *butNewTitleStr = [[NSString alloc] initWithFormat:@"%@%ld%%",NSLocalizedString(@"image_version_Update_ing",nil),(NSInteger)(curProgress*100)];
  172. [_updateNowBut setTitle:butNewTitleStr forState:UIControlStateNormal];
  173. NSString *leftStr = NSLocalizedString(@"image_version_pop_144_tip2_1",nil);
  174. NSString *rightStr = NSLocalizedString(@"image_version_pop_144_tip2_2",nil);
  175. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@%@",leftStr,rightStr];
  176. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  177. NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length);
  178. [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#FF2828" alpha:1.0] range:redRange];
  179. //[noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15.0] range:redRange];
  180. // 设置行间距
  181. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  182. [paragraphStyle setLineSpacing:5]; //设置行间距
  183. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  184. _tip1Lab.attributedText = noteStr;
  185. }
  186. @end