clearCacheAlretViewController.m 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. //
  2. // clearCacheAlretViewController.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/3/29.
  6. //
  7. #import "clearCacheAlretViewController.h"
  8. @interface clearCacheAlretViewController (){
  9. NSString *titleStr;
  10. NSString *msgStr;
  11. NSString *imageStr;
  12. NSString *cancelTitleStr;
  13. NSString *okTitleStr;
  14. BOOL isOkBtnHighlight;
  15. clearCacheAlert_ClickOkBtn didClickOkBtn;
  16. CommonAlert_ClickCancelBtn didClickCanaelBtn;
  17. UIButton *selectBut;
  18. }
  19. @end
  20. @implementation clearCacheAlretViewController
  21. - (id)initWithTiTle:(NSString *)title msg:(NSString *)msg imageStr:(NSString *)image cancelTitle:(NSString *)cancelTitle okTitle:(NSString *)okTitle isOkBtnHighlight:(BOOL)okBtnHighlight didClickOk:(clearCacheAlert_ClickOkBtn)ok didClickCancel:(CommonAlert_ClickCancelBtn)Cancel{
  22. self = [super init];
  23. titleStr = title;
  24. msgStr = msg;
  25. imageStr = image;
  26. cancelTitleStr = cancelTitle;
  27. okTitleStr = okTitle;
  28. isOkBtnHighlight = okBtnHighlight;
  29. didClickOkBtn = ok;
  30. didClickCanaelBtn = Cancel;
  31. return self;
  32. }
  33. - (void)viewDidLoad {
  34. [super viewDidLoad];
  35. // Do any additional setup after loading the view.
  36. [self drawAnyView];
  37. }
  38. - (void)drawAnyView{
  39. [self.view setBackgroundColor:HW000000Color60];
  40. [self.toolBar setHidden:YES];
  41. [self.navigationBar setHidden:YES];
  42. UIView *bgView = [[UIView alloc] init];
  43. [bgView setBackgroundColor:[UIColor whiteColor]];
  44. [bgView.layer setCornerRadius:8.f];
  45. [self.view addSubview:bgView];
  46. [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.centerY.equalTo(self.view.mas_centerY).offset(10*HAUTOSCALE);
  48. make.centerX.equalTo(self.view.mas_centerX);
  49. make.width.mas_equalTo(300.f);
  50. }];
  51. CGFloat curTop = 30.0;
  52. //图片
  53. UIImageView *topImageView = [[UIImageView alloc] init];
  54. //topImageView.backgroundColor = [UIColor redColor];
  55. if(imageStr && imageStr.length > 0){
  56. topImageView.image = [UIImage imageNamed:imageStr];
  57. [bgView addSubview:topImageView];
  58. [topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.width.mas_equalTo(80.f);
  60. make.height.mas_equalTo(80.f);
  61. make.centerX.equalTo(bgView.mas_centerX);;
  62. make.top.mas_equalTo(curTop);
  63. }];
  64. curTop = 30 + 80 + 10.0;
  65. }
  66. /*主标题*/
  67. UILabel *titleLabel = [[UILabel alloc] init];
  68. [titleLabel setTextColor:HW0A132BColor];
  69. [titleLabel setFont:[UIFont boldSystemFontOfSize:16.f]];
  70. [titleLabel setTextAlignment:(NSTextAlignmentCenter)];
  71. [titleLabel setText:titleStr];
  72. [titleLabel setNumberOfLines:0];
  73. if (titleStr.length > 0){
  74. [bgView addSubview:titleLabel];
  75. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.left.mas_equalTo(8.f);
  77. make.right.mas_equalTo(-8.f);
  78. make.top.mas_equalTo(curTop);
  79. }];
  80. }
  81. /*副标题*/
  82. UILabel *msgLabel = [[UILabel alloc] init];
  83. [msgLabel setTextColor:HW333333Color];
  84. [msgLabel setFont:[UIFont systemFontOfSize:15.f]];
  85. [msgLabel setTextAlignment:(NSTextAlignmentCenter)];
  86. [msgLabel setText:msgStr];
  87. [msgLabel setNumberOfLines:0];
  88. if (msgStr.length > 0){
  89. [bgView addSubview:msgLabel];
  90. [msgLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.left.mas_equalTo(8.f);
  92. make.right.mas_equalTo(-8.f);
  93. if (titleStr.length > 0){
  94. make.top.equalTo(titleLabel.mas_bottom).offset(15.f);
  95. }else{
  96. make.top.mas_equalTo(curTop);
  97. }
  98. }];
  99. }
  100. //清理缓存中间添加另外的按钮
  101. selectBut = [[UIButton alloc] init];
  102. [selectBut setImage:[UIImage imageNamed:@"common_did_check"] forState:UIControlStateSelected];
  103. [selectBut setImage:[UIImage imageNamed:@"common_un_check"] forState:UIControlStateNormal];
  104. [selectBut setTitle:NSLocalizedString(@"clear_cache_include_file_Transfer",nil) forState:UIControlStateNormal];
  105. selectBut.titleLabel.font = [UIFont systemFontOfSize:12.0];
  106. [selectBut setTitleColor:[UIColor hwColor:@"#151515" alpha:1.0] forState:UIControlStateNormal];
  107. [selectBut addTarget:self action:@selector(didClickSelectButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  108. [bgView addSubview:selectBut];
  109. [selectBut mas_makeConstraints:^(MASConstraintMaker *make) {
  110. make.left.mas_equalTo(8.f);
  111. make.right.mas_equalTo(-8.f);
  112. if (msgStr.length > 0){
  113. make.top.equalTo(msgLabel.mas_bottom).offset(15.f);
  114. }else{
  115. make.top.equalTo(titleLabel.mas_bottom).offset(25.f);
  116. }
  117. make.height.mas_equalTo(20);
  118. }];
  119. /*双按钮*/
  120. /*取消*/
  121. /*取消按钮*/
  122. UIButton *cancelBtn = [[UIButton alloc] init];
  123. cancelBtn.frame = CGRectMake(0, 0, 115, 48.f);
  124. CGFloat w_btn = 200;
  125. if (okTitleStr.length > 0){
  126. w_btn = 115;
  127. }
  128. // gradient
  129. CAGradientLayer *gl = [CAGradientLayer layer];
  130. gl.frame = CGRectMake(0,0,w_btn,48.f);
  131. gl.startPoint = CGPointMake(0, 0.5);
  132. gl.endPoint = CGPointMake(1, 0.5);
  133. gl.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor];
  134. gl.locations = @[@(0), @(1.0f)];
  135. if(!isOkBtnHighlight){
  136. [cancelBtn.layer addSublayer:gl];
  137. [cancelBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  138. }
  139. else{
  140. [cancelBtn setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  141. [cancelBtn setBackgroundColor:HWE3E8F1Color];
  142. }
  143. [cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  144. [cancelBtn setTitle:cancelTitleStr forState:(UIControlStateNormal)];
  145. [cancelBtn.titleLabel setFont:[UIFont systemFontOfSize:16.f]];
  146. [cancelBtn.layer setCornerRadius:8.f];
  147. cancelBtn.clipsToBounds = YES;
  148. cancelBtn.tag = 999;
  149. [bgView addSubview:cancelBtn];
  150. [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  151. if (okTitleStr.length > 0){
  152. make.left.mas_equalTo(24);
  153. }else{
  154. make.centerX.equalTo(bgView.mas_centerX);
  155. }
  156. // if (msgStr.length > 0){
  157. // make.top.equalTo(msgLabel.mas_bottom).offset(15.f);
  158. // }else{
  159. // make.top.equalTo(titleLabel.mas_bottom).offset(25.f);
  160. // }
  161. make.top.equalTo(selectBut.mas_bottom).offset(25.f);
  162. make.width.mas_equalTo(w_btn);
  163. make.bottom.equalTo(bgView.mas_bottom).offset(-30.f);
  164. make.height.mas_equalTo(48.f);
  165. }];
  166. if (okTitleStr.length > 0){
  167. /*残忍拒绝*/
  168. UIButton *okBtn = [[UIButton alloc] init];
  169. if(!isOkBtnHighlight){
  170. [okBtn setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  171. [okBtn setBackgroundColor:HWE3E8F1Color];
  172. }
  173. else{
  174. [okBtn.layer addSublayer:gl];
  175. [okBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  176. }
  177. [okBtn addTarget:self action:@selector(okBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  178. [okBtn setTitle:okTitleStr forState:(UIControlStateNormal)];
  179. //[okBtn setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  180. [okBtn.titleLabel setFont:[UIFont systemFontOfSize:16.f]];
  181. [okBtn.layer setCornerRadius:8.f];
  182. //[okBtn setBackgroundColor:HWE3E8F1Color];
  183. okBtn.clipsToBounds = YES;
  184. [bgView addSubview:okBtn];
  185. [okBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  186. make.right.mas_equalTo(-24.f);
  187. make.width.mas_equalTo(w_btn);
  188. make.top.equalTo(cancelBtn.mas_top);
  189. make.height.mas_equalTo(48.f);
  190. }];
  191. }
  192. }
  193. - (void)cancelBtnClick{
  194. [self dismissViewControllerAnimated:YES completion:^{
  195. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  196. if(self->didClickCanaelBtn){
  197. self->didClickCanaelBtn();
  198. }
  199. });
  200. }];
  201. }
  202. - (void)okBtnClick{
  203. [self dismissViewControllerAnimated:YES completion:^{
  204. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  205. if(self->didClickOkBtn){
  206. self->didClickOkBtn(self->selectBut.selected);
  207. }
  208. });
  209. }];
  210. }
  211. - (void)didClickSelectButtonFun:(UIButton*)but
  212. {
  213. but.selected = !but.selected;
  214. }
  215. @end