ComontAlretViewController.m 6.0 KB

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