HaveNewVersionView.m 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. //
  2. // HaveNewVersionView.m
  3. // VclustersGemini
  4. //
  5. // Created by APPLE on 2020/2/24.
  6. // Copyright © 2020 APPLE. All rights reserved.
  7. //
  8. #import "HaveNewVersionView.h"
  9. @interface HaveNewVersionView ()<UITableViewDelegate,UITableViewDataSource>
  10. @property (nonatomic,strong) NSMutableArray *dataSource;
  11. @end
  12. @implementation HaveNewVersionView
  13. @synthesize titleLabel;
  14. @synthesize detailLabel;
  15. @synthesize bgView;
  16. @synthesize deleteBtn;
  17. static HaveNewVersionView * _instance;
  18. + (instancetype)shardInstance {
  19. static dispatch_once_t HaveNewVersionViewonceToken;
  20. dispatch_once(&HaveNewVersionViewonceToken, ^{
  21. _instance = [[self alloc] init];
  22. });
  23. return _instance;
  24. }
  25. - (id)initWithFrame:(CGRect)frame
  26. {
  27. self = [super initWithFrame:frame];
  28. if (self)
  29. {
  30. [self drawAnyView];
  31. }
  32. return self;
  33. }
  34. - (void)drawAnyView
  35. {
  36. self.tag = 111111;
  37. [self setBackgroundColor:HW000000Color60];
  38. bgView = [[UIView alloc] init];
  39. [bgView setBackgroundColor:[UIColor whiteColor]];
  40. [bgView.layer setCornerRadius:8.f];
  41. [self addSubview:bgView];
  42. [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.height.mas_equalTo(328.f);
  44. make.width.mas_equalTo(300.f);
  45. make.centerX.equalTo(self.mas_centerX);
  46. make.centerY.equalTo(self.mas_centerY);
  47. }];
  48. // 图片
  49. UIImageView *topImageView = [[UIImageView alloc] init];
  50. topImageView.image = [UIImage imageNamed:@"gengxinbeijing_pic"];
  51. topImageView.contentMode = UIViewContentModeScaleAspectFit;
  52. [bgView addSubview:topImageView];
  53. [topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.top.mas_equalTo(bgView.mas_top);
  55. make.left.mas_equalTo(bgView.mas_left);
  56. make.right.mas_equalTo(bgView.mas_right);
  57. make.height.mas_equalTo(141);
  58. }];
  59. /*提示文字*/
  60. UILabel *tipsLabel = [[UILabel alloc] init];
  61. [tipsLabel setText:NSLocalizedString(@"app_update_new_version_tips",nil)];
  62. [tipsLabel setTextColor:HW0A132BColor];
  63. [tipsLabel setFont:[UIFont systemFontOfSize:14.f]];
  64. [tipsLabel setTextAlignment:(NSTextAlignmentCenter)];
  65. [tipsLabel setNumberOfLines:0];
  66. [bgView addSubview:tipsLabel];
  67. [tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.top.equalTo(topImageView.mas_bottom).offset(30.f);
  69. make.left.mas_equalTo(20);
  70. make.right.mas_equalTo(-20);
  71. make.height.mas_equalTo(60);
  72. }];
  73. /*删除按钮*/
  74. deleteBtn = [[UIButton alloc] init];
  75. [deleteBtn setBackgroundColor:[UIColor clearColor]];
  76. [deleteBtn setImage:[UIImage imageNamed:@"guanbi_bai_icon"] forState:(UIControlStateNormal)];
  77. [deleteBtn addTarget:self action:@selector(deleteBtnPressed) forControlEvents:(UIControlEventTouchUpInside)];
  78. [bgView addSubview:deleteBtn];
  79. [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.height.mas_equalTo(45.f);
  81. make.width.mas_equalTo(45.f);
  82. make.right.mas_equalTo(bgView.mas_right).mas_offset(0);
  83. make.top.mas_equalTo(bgView.mas_top).mas_offset(0);
  84. }];
  85. deleteBtn.hidden = YES;
  86. // 分割线
  87. UIView *line = [[UIView alloc] init];
  88. line.backgroundColor = HWCCCCCCColor;
  89. [bgView addSubview:line];
  90. [line mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.left.mas_equalTo(0);
  92. make.right.mas_equalTo(0);
  93. make.height.mas_equalTo(1);
  94. make.bottom.mas_equalTo(-92);
  95. }];
  96. // /*确定按钮*/
  97. // UIButton *okBtn = [[UIButton alloc] init];
  98. // [okBtn setBackgroundImage:[UIImage imageNamed:@"login_select_corner"] forState:(UIControlStateNormal)];
  99. // [okBtn setTitle:@"更新" forState:(UIControlStateNormal)];
  100. // [okBtn.titleLabel setFont:[UIFont systemFontOfSize:14.f]];
  101. // [okBtn addTarget:self action:@selector(updateBtnPressed) forControlEvents:(UIControlEventTouchUpInside)];
  102. // [okBtn.layer setCornerRadius:20.f];
  103. // okBtn.layer.masksToBounds = YES;
  104. // [bgView addSubview:okBtn];
  105. //
  106. // [okBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  107. // make.height.mas_equalTo(40.f);
  108. // make.width.mas_equalTo(168.f);
  109. // make.centerX.equalTo(bgView.mas_centerX);
  110. // make.bottom.mas_equalTo(-20.f);
  111. // }];
  112. UIButton *updatekBtn = [[UIButton alloc] init];
  113. updatekBtn.frame = CGRectMake(0, 0, 160.f, 48.f);
  114. // gradient
  115. CAGradientLayer *gl = [CAGradientLayer layer];
  116. gl.frame = CGRectMake(0,0,160.f,48.f);
  117. gl.startPoint = CGPointMake(0, 0.5);
  118. gl.endPoint = CGPointMake(1, 0.5);
  119. gl.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor];
  120. gl.locations = @[@(0), @(1.0f)];
  121. [updatekBtn.layer addSublayer:gl];
  122. [updatekBtn addTarget:self action:@selector(updateBtnPressed) forControlEvents:(UIControlEventTouchUpInside)];
  123. [updatekBtn setTitle:NSLocalizedString(@"app_update_update",nil) forState:(UIControlStateNormal)];
  124. [updatekBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  125. [updatekBtn.titleLabel setFont:[UIFont systemFontOfSize:16.f]];
  126. [updatekBtn.layer setCornerRadius:8.f];
  127. updatekBtn.clipsToBounds = YES;
  128. [bgView addSubview:updatekBtn];
  129. [updatekBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  130. make.centerX.equalTo(bgView.mas_centerX);
  131. make.width.mas_equalTo(160.f);
  132. make.bottom.mas_equalTo(-20.f);
  133. make.height.mas_equalTo(48.f);
  134. }];
  135. // UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 1, 1) style:(UITableViewStylePlain)];
  136. // tableView.delegate = self;
  137. // tableView.dataSource = self;
  138. // [tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  139. // [tableView setSeparatorColor:[UIColor clearColor]];
  140. // [tableView setBackgroundColor:[UIColor clearColor]];
  141. // if (@available(iOS 15.0, *)) {
  142. // tableView.sectionHeaderTopPadding = 0;
  143. // }
  144. // [bgView addSubview:tableView];
  145. // [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  146. // make.left.mas_equalTo(0);
  147. // make.right.mas_equalTo(0);
  148. // make.top.mas_equalTo(topImageView.mas_bottom);
  149. // make.bottom.mas_equalTo(line.mas_top);
  150. // }];
  151. }
  152. - (void)deleteBtnPressed
  153. {
  154. [self removeFromSuperview];
  155. self.isShow = NO;
  156. if ([_delegate respondsToSelector:@selector(closeBtnBePressed)]) {
  157. [_delegate closeBtnBePressed];
  158. }
  159. }
  160. - (void)updateBtnPressed {
  161. if (!self.versionModel.necessary) { // 非强制更新
  162. self.isShow = NO;
  163. [self removeFromSuperview];
  164. if ([_delegate respondsToSelector:@selector(closeBtnBePressed)]) {
  165. [_delegate closeBtnBePressed];
  166. }
  167. }
  168. /*跳转蒲公英*/
  169. }
  170. #pragma mark - 列表委托
  171. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  172. return 1;
  173. }
  174. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  175. return self.dataSource.count;
  176. }
  177. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  178. static NSString *identifier = @"newVersionInfoCellidentifier";
  179. NSInteger row = indexPath.row;
  180. NSString *tipsString = self.dataSource[row];
  181. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  182. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  183. UITableViewCell *payTypecell = [tableView dequeueReusableCellWithIdentifier:identifier];
  184. payTypecell.selectionStyle = UITableViewCellSelectionStyleNone;
  185. if (!cell)
  186. {
  187. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  188. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  189. [cell setBackgroundColor:[UIColor clearColor]];
  190. /*文字*/
  191. [cell.textLabel setFont:[UIFont systemFontOfSize:14.f]];
  192. [cell.textLabel setTextColor:HWCFD1D4Color];
  193. cell.textLabel.numberOfLines = 0;
  194. [cell.textLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  195. make.left.mas_equalTo(15);
  196. make.right.mas_equalTo(-15);
  197. make.top.mas_equalTo(5);
  198. make.bottom.mas_equalTo(5);
  199. }];
  200. }
  201. cell.textLabel.text = [NSString stringWithFormat:@"·%@",tipsString];
  202. return cell;
  203. }
  204. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  205. return UITableViewAutomaticDimension;
  206. }
  207. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  208. UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 37)];
  209. bgView.backgroundColor = HWF5F7FAColor;
  210. UILabel *label1 = [[UILabel alloc] init];
  211. label1.text = [NSString stringWithFormat:@"发现新版本(%@)", self.versionModel.versionNumber];
  212. label1.textColor = HWCFD1D4Color;
  213. label1.font = [UIFont boldSystemFontOfSize:14.f];
  214. [bgView addSubview:label1];
  215. [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
  216. make.left.mas_equalTo(15);
  217. make.top.mas_equalTo(10);
  218. }];
  219. UILabel *label2 = [[UILabel alloc] init];
  220. label2.text = [NSString stringWithFormat:@"大小:%@MB", self.versionModel.fileSize];
  221. label2.textColor = HWF5F7FAColor;
  222. label2.font = [UIFont systemFontOfSize:10.f];
  223. [bgView addSubview:label2];
  224. [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
  225. make.left.mas_equalTo(label1.mas_right).mas_offset(5);
  226. make.centerY.mas_equalTo(label1.mas_centerY);
  227. }];
  228. return bgView;
  229. }
  230. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  231. return 35;
  232. }
  233. - (NSMutableArray *)dataSource {
  234. if (!_dataSource) {
  235. NSArray *tips = [self.versionModel.versionInfo componentsSeparatedByString:@"&&"];
  236. _dataSource = [NSMutableArray arrayWithArray:tips];
  237. }
  238. return _dataSource;
  239. }
  240. @end