ComontAlretDeleteTypeViewController.m 8.8 KB

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