GDYLimitAlert.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // GDYLimitAlert.m
  3. // iphoneLive
  4. //
  5. // Created by YB007 on 2022/4/9.
  6. // Copyright © 2022 cat. All rights reserved.
  7. //
  8. #import "GDYLimitAlert.h"
  9. @interface GDYLimitAlert()
  10. @property(nonatomic,copy)LimitBlock limitEvent;
  11. @property(nonatomic,strong)NSDictionary *limitDic;
  12. @property(nonatomic,strong)UIView *bgView;
  13. @end
  14. @implementation GDYLimitAlert
  15. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch; {
  16. if ([touch.view isDescendantOfView:self.bgView]) {
  17. return NO;
  18. }
  19. return YES;
  20. }
  21. -(void)dissmissView {
  22. [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  23. [self removeFromSuperview];
  24. }
  25. +(instancetype)showLimitWithDic:(NSDictionary *)limitDic complete:(LimitBlock)complete{
  26. GDYLimitAlert *view = [[GDYLimitAlert alloc]init];
  27. view.frame = CGRectMake(0, 0, _window_width, _window_height);
  28. view.limitDic = limitDic;
  29. view.limitEvent = complete;
  30. //[[YBBaseAppDelegate sharedAppDelegate].topViewController.view addSubview:view];
  31. [[UIApplication sharedApplication].delegate.window addSubview:view];
  32. [view createUI];
  33. return view;
  34. }
  35. -(void)createUI {
  36. /*
  37. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dissmissView)];
  38. tap.delegate = self;
  39. [self addGestureRecognizer:tap];
  40. */
  41. _bgView = [[UIView alloc]init];
  42. _bgView.backgroundColor = UIColor.whiteColor;
  43. _bgView.layer.cornerRadius = 10;
  44. _bgView.layer.masksToBounds = YES;
  45. [self addSubview:_bgView];
  46. [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.width.equalTo(self.mas_width).multipliedBy(0.7);
  48. make.centerX.equalTo(self);
  49. make.centerY.equalTo(self.mas_centerY).multipliedBy(0.9);
  50. }];
  51. UILabel *titleL = [[UILabel alloc]init];
  52. titleL.textColor = RGB_COLOR(@"#323232", 1);
  53. titleL.font = [UIFont boldSystemFontOfSize:16];
  54. titleL.numberOfLines = 0;
  55. titleL.text = minstr([_limitDic valueForKey:@"title"]);
  56. titleL.textAlignment = NSTextAlignmentCenter;
  57. [_bgView addSubview:titleL];
  58. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.width.lessThanOrEqualTo(_bgView.mas_width).offset(-30);
  60. make.top.equalTo(_bgView.mas_top).offset(20);
  61. make.centerX.equalTo(_bgView);
  62. }];
  63. UILabel *contentL = [[UILabel alloc]init];
  64. contentL.textColor = RGB_COLOR(@"#323232", 1);
  65. contentL.font = SYS_Font(15);
  66. contentL.numberOfLines = 0;
  67. NSString *limitMsg = minstr([_limitDic valueForKey:@"msg"]);
  68. NSMutableAttributedString *m_att = [[NSMutableAttributedString alloc]initWithString:limitMsg];
  69. if ([limitMsg containsString:@":"]) {
  70. NSRange range = [limitMsg rangeOfString:@":"];
  71. int length = (int)limitMsg.length - (int)range.location - 1;
  72. NSRange newRange = NSMakeRange(range.location+1, length);
  73. [m_att addAttributes:@{NSForegroundColorAttributeName:Pink_Cor} range:newRange];
  74. }
  75. if ([limitMsg containsString:@":"]) {
  76. NSRange range = [limitMsg rangeOfString:@":"];
  77. int length = (int)limitMsg.length - (int)range.location - 1;
  78. NSRange newRange = NSMakeRange(range.location+1, length);
  79. [m_att addAttributes:@{NSForegroundColorAttributeName:Pink_Cor} range:newRange];
  80. }
  81. contentL.attributedText = m_att;
  82. contentL.textAlignment = NSTextAlignmentCenter;
  83. [_bgView addSubview:contentL];
  84. [contentL mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.width.lessThanOrEqualTo(_bgView.mas_width).offset(-30);
  86. make.top.equalTo(titleL.mas_bottom).offset(15);
  87. make.centerX.equalTo(_bgView);
  88. }];
  89. UIButton *knowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  90. [knowBtn setTitle:YZMsg(@"知道了") forState:0];
  91. knowBtn.backgroundColor = Pink_Cor;
  92. knowBtn.titleLabel.font = SYS_Font(13);
  93. [knowBtn setTitleColor:RGB_COLOR(@"#ffffff", 1) forState:0];
  94. knowBtn.layer.cornerRadius = 5;
  95. knowBtn.layer.masksToBounds = YES;
  96. [knowBtn addTarget:self action:@selector(dissmissView) forControlEvents:UIControlEventTouchUpInside];
  97. [_bgView addSubview:knowBtn];
  98. [knowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  99. make.width.equalTo(_bgView.mas_width).multipliedBy(0.63);
  100. make.top.equalTo(contentL.mas_bottom).offset(20);
  101. make.height.mas_equalTo(30);
  102. make.centerX.equalTo(_bgView);
  103. make.bottom.equalTo(_bgView.mas_bottom).offset(-20);
  104. }];
  105. }
  106. @end