ComontAlretType2ViewController.m 8.8 KB

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