imageVersionRenewTipView.m 9.7 KB

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