ComontAlretViewController.m 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. //
  2. // ComontAlretViewController.m
  3. // 隐私保护
  4. //
  5. // Created by APPLE on 2023/8/30.
  6. //
  7. #import "ComontAlretViewController.h"
  8. #import <Masonry.h>
  9. @interface ComontAlretViewController (){
  10. NSString *titleStr;
  11. NSString *msgStr;
  12. NSString *cancelTitleStr;
  13. NSString *okTitleStr;
  14. BOOL isOkBtnHighlight;
  15. CommonAlert_ClickOkBtn didClickOkBtn;
  16. CommonAlert_ClickCancelBtn didClickCanaelBtn;
  17. }
  18. @end
  19. @implementation ComontAlretViewController
  20. @synthesize delegate;
  21. - (id)initWithTiTle:(NSString *)title msg:(NSString *)msg cancelTitle:(NSString *)cancelTitle okTitle:(NSString *)okTitle isOkBtnHighlight:(BOOL)okBtnHighlight didClickOk:(CommonAlert_ClickOkBtn)ok didClickCancel:(CommonAlert_ClickCancelBtn)Cancel{
  22. self = [super init];
  23. titleStr = title;
  24. msgStr = msg;
  25. cancelTitleStr = cancelTitle;
  26. okTitleStr = okTitle;
  27. isOkBtnHighlight = okBtnHighlight;
  28. didClickOkBtn = ok;
  29. didClickCanaelBtn = Cancel;
  30. return self;
  31. }
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. // Do any additional setup after loading the view.
  35. [self drawAnyView];
  36. }
  37. - (void)drawAnyView{
  38. [self.view setBackgroundColor:HW000000Color60];
  39. [self.toolBar setHidden:YES];
  40. [self.navigationBar setHidden:YES];
  41. UIView *bgView = [[UIView alloc] init];
  42. [bgView setBackgroundColor:[UIColor whiteColor]];
  43. [bgView.layer setCornerRadius:8.f];
  44. [self.view addSubview:bgView];
  45. [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.centerY.equalTo(self.view.mas_centerY).offset(10*HAUTOSCALE);
  47. make.centerX.equalTo(self.view.mas_centerX);
  48. make.width.mas_equalTo(300.f);
  49. }];
  50. /*主标题*/
  51. UILabel *titleLabel = [[UILabel alloc] init];
  52. [titleLabel setTextColor:HW0A132BColor];
  53. [titleLabel setFont:[UIFont boldSystemFontOfSize:16.f]];
  54. [titleLabel setTextAlignment:(NSTextAlignmentCenter)];
  55. [titleLabel setText:titleStr];
  56. [titleLabel setNumberOfLines:0];
  57. if (titleStr.length > 0){
  58. [bgView addSubview:titleLabel];
  59. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.left.mas_equalTo(8.f);
  61. make.right.mas_equalTo(-8.f);
  62. make.top.mas_equalTo(30.f);
  63. }];
  64. }
  65. /*副标题*/
  66. UILabel *msgLabel = [[UILabel alloc] init];
  67. [msgLabel setTextColor:HW333333Color];
  68. [msgLabel setFont:[UIFont systemFontOfSize:15.f]];
  69. [msgLabel setTextAlignment:(NSTextAlignmentCenter)];
  70. [msgLabel setText:msgStr];
  71. [msgLabel setNumberOfLines:0];
  72. if (msgStr.length > 0){
  73. [bgView addSubview:msgLabel];
  74. [msgLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.left.mas_equalTo(8.f);
  76. make.right.mas_equalTo(-8.f);
  77. if (titleStr.length > 0){
  78. make.top.equalTo(titleLabel.mas_bottom).offset(15.f);
  79. }else{
  80. make.top.mas_equalTo(30.f);
  81. }
  82. }];
  83. }
  84. /*双按钮*/
  85. /*取消*/
  86. /*取消按钮*/
  87. UIButton *cancelBtn = [[UIButton alloc] init];
  88. cancelBtn.frame = CGRectMake(0, 0, 115, 48.f);
  89. CGFloat w_btn = 200;
  90. if (okTitleStr.length > 0){
  91. w_btn = 115;
  92. }
  93. // gradient
  94. CAGradientLayer *gl = [CAGradientLayer layer];
  95. gl.frame = CGRectMake(0,0,w_btn,48.f);
  96. gl.startPoint = CGPointMake(0, 0.5);
  97. gl.endPoint = CGPointMake(1, 0.5);
  98. gl.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor];
  99. gl.locations = @[@(0), @(1.0f)];
  100. if(!isOkBtnHighlight){
  101. [cancelBtn.layer addSublayer:gl];
  102. [cancelBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  103. }
  104. else{
  105. [cancelBtn setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  106. [cancelBtn setBackgroundColor:HWE3E8F1Color];
  107. }
  108. [cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  109. [cancelBtn setTitle:cancelTitleStr forState:(UIControlStateNormal)];
  110. [cancelBtn.titleLabel setFont:[UIFont systemFontOfSize:16.f]];
  111. [cancelBtn.layer setCornerRadius:8.f];
  112. cancelBtn.clipsToBounds = YES;
  113. [bgView addSubview:cancelBtn];
  114. [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  115. if (okTitleStr.length > 0){
  116. make.left.mas_equalTo(24);
  117. }else{
  118. make.centerX.equalTo(bgView.mas_centerX);
  119. }
  120. if (msgStr.length > 0){
  121. make.top.equalTo(msgLabel.mas_bottom).offset(15.f);
  122. }else{
  123. make.top.equalTo(titleLabel.mas_bottom).offset(25.f);
  124. }
  125. make.width.mas_equalTo(w_btn);
  126. make.bottom.equalTo(bgView.mas_bottom).offset(-30.f);
  127. make.height.mas_equalTo(48.f);
  128. }];
  129. if (okTitleStr.length > 0){
  130. /*残忍拒绝*/
  131. UIButton *okBtn = [[UIButton alloc] init];
  132. if(!isOkBtnHighlight){
  133. [okBtn setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  134. [okBtn setBackgroundColor:HWE3E8F1Color];
  135. }
  136. else{
  137. [okBtn.layer addSublayer:gl];
  138. [okBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  139. }
  140. [okBtn addTarget:self action:@selector(okBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  141. [okBtn setTitle:okTitleStr forState:(UIControlStateNormal)];
  142. //[okBtn setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  143. [okBtn.titleLabel setFont:[UIFont systemFontOfSize:16.f]];
  144. [okBtn.layer setCornerRadius:8.f];
  145. //[okBtn setBackgroundColor:HWE3E8F1Color];
  146. okBtn.clipsToBounds = YES;
  147. [bgView addSubview:okBtn];
  148. [okBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  149. make.right.mas_equalTo(-24.f);
  150. make.width.mas_equalTo(w_btn);
  151. make.top.equalTo(cancelBtn.mas_top);
  152. make.height.mas_equalTo(48.f);
  153. }];
  154. }
  155. }
  156. //- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  157. // [self dismissViewControllerAnimated:YES completion:^{
  158. // ;
  159. // }];
  160. //}
  161. - (void)cancelBtnClick{
  162. [self dismissViewControllerAnimated:YES completion:^{
  163. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  164. if ([self->delegate respondsToSelector:@selector(CommonAlertCancelBtnClickPressed)]){
  165. [self->delegate CommonAlertCancelBtnClickPressed];
  166. }
  167. if(self->didClickCanaelBtn){
  168. self->didClickCanaelBtn();
  169. }
  170. });
  171. }];
  172. }
  173. - (void)okBtnClick{
  174. [self dismissViewControllerAnimated:YES completion:^{
  175. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  176. if ([self->delegate respondsToSelector:@selector(CommonAlertokBtnClickPressed)]){
  177. [self->delegate CommonAlertokBtnClickPressed];
  178. }
  179. if(self->didClickOkBtn){
  180. self->didClickOkBtn();
  181. }
  182. });
  183. }];
  184. }
  185. /*
  186. #pragma mark - Navigation
  187. // In a storyboard-based application, you will often want to do a little preparation before navigation
  188. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  189. // Get the new view controller using [segue destinationViewController].
  190. // Pass the selected object to the new view controller.
  191. }
  192. */
  193. @end