clearCacheAlretViewController.m 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. //
  2. // clearCacheAlretViewController.m
  3. // Private-X
  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. ///获取设备当前地区的代码和APP语言环境
  101. NSString *languageCode = [NSLocale preferredLanguages][0];
  102. CGFloat butHeight = 20.0;
  103. //目前支持 中文(简体 繁体) 英文 日语
  104. if([languageCode rangeOfString:@"zh-Hans"].location != NSNotFound)
  105. {
  106. }
  107. else if([languageCode rangeOfString:@"zh-Hant"].location != NSNotFound)
  108. {
  109. }
  110. else{
  111. butHeight = 40.0;
  112. }
  113. //清理缓存中间添加另外的按钮
  114. selectBut = [[UIButton alloc] init];
  115. [selectBut setImage:[UIImage imageNamed:@"common_did_check"] forState:UIControlStateSelected];
  116. [selectBut setImage:[UIImage imageNamed:@"common_un_check"] forState:UIControlStateNormal];
  117. [selectBut setTitle:NSLocalizedString(@"clear_cache_include_file_Transfer",nil) forState:UIControlStateNormal];
  118. selectBut.titleLabel.font = [UIFont systemFontOfSize:12.0];
  119. selectBut.titleLabel.numberOfLines = 0;
  120. [selectBut setTitleColor:[UIColor hwColor:@"#151515" alpha:1.0] forState:UIControlStateNormal];
  121. [selectBut addTarget:self action:@selector(didClickSelectButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  122. [bgView addSubview:selectBut];
  123. [selectBut mas_makeConstraints:^(MASConstraintMaker *make) {
  124. make.left.mas_equalTo(8.f);
  125. make.right.mas_equalTo(-8.f);
  126. if (msgStr.length > 0){
  127. make.top.equalTo(msgLabel.mas_bottom).offset(15.f);
  128. }else{
  129. make.top.equalTo(titleLabel.mas_bottom).offset(25.f);
  130. }
  131. make.height.mas_equalTo(butHeight);
  132. }];
  133. /*双按钮*/
  134. /*取消*/
  135. /*取消按钮*/
  136. UIButton *cancelBtn = [[UIButton alloc] init];
  137. cancelBtn.frame = CGRectMake(0, 0, 115, 48.f);
  138. CGFloat w_btn = 200;
  139. if (okTitleStr.length > 0){
  140. w_btn = 115;
  141. }
  142. // gradient
  143. CAGradientLayer *gl = [CAGradientLayer layer];
  144. gl.frame = CGRectMake(0,0,w_btn,48.f);
  145. gl.startPoint = CGPointMake(0, 0.5);
  146. gl.endPoint = CGPointMake(1, 0.5);
  147. gl.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor];
  148. gl.locations = @[@(0), @(1.0f)];
  149. if(!isOkBtnHighlight){
  150. [cancelBtn.layer addSublayer:gl];
  151. [cancelBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  152. }
  153. else{
  154. [cancelBtn setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  155. [cancelBtn setBackgroundColor:HWE3E8F1Color];
  156. }
  157. [cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  158. [cancelBtn setTitle:cancelTitleStr forState:(UIControlStateNormal)];
  159. [cancelBtn.titleLabel setFont:[UIFont systemFontOfSize:16.f]];
  160. [cancelBtn.layer setCornerRadius:8.f];
  161. cancelBtn.clipsToBounds = YES;
  162. cancelBtn.tag = 999;
  163. [bgView addSubview:cancelBtn];
  164. [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  165. if (okTitleStr.length > 0){
  166. make.left.mas_equalTo(24);
  167. }else{
  168. make.centerX.equalTo(bgView.mas_centerX);
  169. }
  170. // if (msgStr.length > 0){
  171. // make.top.equalTo(msgLabel.mas_bottom).offset(15.f);
  172. // }else{
  173. // make.top.equalTo(titleLabel.mas_bottom).offset(25.f);
  174. // }
  175. make.top.equalTo(selectBut.mas_bottom).offset(25.f);
  176. make.width.mas_equalTo(w_btn);
  177. make.bottom.equalTo(bgView.mas_bottom).offset(-30.f);
  178. make.height.mas_equalTo(48.f);
  179. }];
  180. if (okTitleStr.length > 0){
  181. /*残忍拒绝*/
  182. UIButton *okBtn = [[UIButton alloc] init];
  183. if(!isOkBtnHighlight){
  184. [okBtn setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  185. [okBtn setBackgroundColor:HWE3E8F1Color];
  186. }
  187. else{
  188. [okBtn.layer addSublayer:gl];
  189. [okBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  190. }
  191. [okBtn addTarget:self action:@selector(okBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  192. [okBtn setTitle:okTitleStr forState:(UIControlStateNormal)];
  193. //[okBtn setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  194. [okBtn.titleLabel setFont:[UIFont systemFontOfSize:16.f]];
  195. [okBtn.layer setCornerRadius:8.f];
  196. //[okBtn setBackgroundColor:HWE3E8F1Color];
  197. okBtn.clipsToBounds = YES;
  198. [bgView addSubview:okBtn];
  199. [okBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  200. make.right.mas_equalTo(-24.f);
  201. make.width.mas_equalTo(w_btn);
  202. make.top.equalTo(cancelBtn.mas_top);
  203. make.height.mas_equalTo(48.f);
  204. }];
  205. }
  206. }
  207. - (void)cancelBtnClick{
  208. [self dismissViewControllerAnimated:YES completion:^{
  209. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  210. if(self->didClickCanaelBtn){
  211. self->didClickCanaelBtn();
  212. }
  213. });
  214. }];
  215. }
  216. - (void)okBtnClick{
  217. [self dismissViewControllerAnimated:YES completion:^{
  218. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  219. if(self->didClickOkBtn){
  220. self->didClickOkBtn(self->selectBut.selected);
  221. }
  222. });
  223. }];
  224. }
  225. - (void)didClickSelectButtonFun:(UIButton*)but
  226. {
  227. but.selected = !but.selected;
  228. }
  229. @end