imageVersionRenewTipView.m 8.8 KB

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