JXRegisterShowView.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //
  2. // JXRegisterShowView.m
  3. // shiku_im
  4. //
  5. // Created by 123 on 2020/5/18.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JXRegisterShowView.h"
  9. @interface JXRegisterShowView()<UITextViewDelegate>
  10. @property (nonatomic,weak) JXRegisterShowView *show;
  11. @property (nonatomic,weak) UILabel *titleL;
  12. @end
  13. @implementation JXRegisterShowView
  14. -(instancetype)initWithFrame:(CGRect)frame{
  15. if (self=[super initWithFrame:frame]) {
  16. self.userInteractionEnabled=YES;
  17. UIView *backView=[[UIView alloc]init];
  18. backView.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.3];
  19. backView.userInteractionEnabled=YES;
  20. [self addSubview:backView];
  21. [backView mas_makeConstraints:^(MASConstraintMaker *make) {
  22. make.top.mas_equalTo(0);
  23. make.left.and.right.mas_equalTo(0);
  24. make.bottom.mas_equalTo(0);
  25. }];
  26. UIView *whiteShowView=[[UIView alloc]init];
  27. whiteShowView.backgroundColor=[UIColor colorWithWhite:1.0 alpha:1.0];
  28. whiteShowView.layer.cornerRadius=15;
  29. whiteShowView.layer.masksToBounds=YES;
  30. [backView addSubview:whiteShowView];
  31. [whiteShowView mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.centerX.mas_equalTo(backView.mas_centerX);
  33. make.centerY.mas_equalTo(backView.mas_centerY);
  34. make.width.mas_equalTo(JX_SCREEN_WIDTH-100);
  35. make.height.mas_equalTo(380);
  36. }];
  37. UILabel *titleL=[[UILabel alloc]init];
  38. titleL.font=[UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  39. titleL.text=@"温馨提示";
  40. titleL.textAlignment=NSTextAlignmentCenter;
  41. [whiteShowView addSubview:titleL];
  42. self.titleL=titleL;
  43. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.top.mas_equalTo(15);
  45. make.left.mas_equalTo(30);
  46. make.right.mas_equalTo(-30);
  47. }];
  48. UITextView *textView=[[UITextView alloc]init];
  49. textView.font=[UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  50. [whiteShowView addSubview:textView];
  51. textView.delegate=self;
  52. textView.selectable=NO;
  53. self.textView=textView;
  54. [textView mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.top.mas_equalTo(titleL.mas_bottom).mas_equalTo(20);
  56. make.left.mas_equalTo(30);
  57. make.right.mas_equalTo(-30);
  58. make.height.mas_equalTo(240);
  59. }];
  60. UIButton *tongYiBtn=[[UIButton alloc]init];
  61. tongYiBtn.titleLabel.font=[UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  62. [tongYiBtn setTitle:@"同意" forState:UIControlStateNormal];
  63. tongYiBtn.backgroundColor=kRGBColor(227, 89, 89);
  64. tongYiBtn.layer.cornerRadius=6;
  65. tongYiBtn.layer.masksToBounds=YES;
  66. [whiteShowView addSubview:tongYiBtn];
  67. self.tongYiBtn=tongYiBtn;
  68. [tongYiBtn addTarget:self action:@selector(tongyiBtn:) forControlEvents:UIControlEventTouchUpInside];
  69. [tongYiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.bottom.mas_equalTo(-23);
  71. make.height.mas_equalTo(38);
  72. make.width.mas_equalTo(94);
  73. make.centerX.mas_equalTo(whiteShowView.mas_centerX);
  74. }];
  75. [self thirdBtnAction];
  76. }
  77. return self;
  78. }
  79. - (void)thirdBtnAction {
  80. __block NSInteger second = 10;
  81. //(1)
  82. dispatch_queue_t quene = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  83. //(2)
  84. dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, quene);
  85. //(3)
  86. dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC, 0 * NSEC_PER_SEC);
  87. //(4)
  88. dispatch_source_set_event_handler(timer, ^{
  89. dispatch_async(dispatch_get_main_queue(), ^{
  90. if (second == 0) {
  91. self.tongYiBtn.userInteractionEnabled = YES;
  92. [self.tongYiBtn setTitle:[NSString stringWithFormat:@"同意"] forState:UIControlStateNormal];
  93. second = 10;
  94. _tongYiBtn.backgroundColor=kRGBColor(227, 89, 89);
  95. //(6)
  96. dispatch_cancel(timer);
  97. } else {
  98. self.tongYiBtn.userInteractionEnabled = NO;
  99. [self.tongYiBtn setTitle:[NSString stringWithFormat:@"同意(%ld)",(long)second] forState:UIControlStateNormal];
  100. _tongYiBtn.backgroundColor=kRGBColor(124, 124, 124);
  101. second--;
  102. }
  103. });
  104. });
  105. //(5)
  106. dispatch_resume(timer);
  107. }
  108. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
  109. if ([text isEqualToString:@"\n"]) {
  110. return NO;
  111. }
  112. return YES;
  113. }
  114. +(void)showView{
  115. JXRegisterShowView *show=[[JXRegisterShowView alloc]init];
  116. show.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.7];
  117. show.frame=[UIScreen mainScreen].bounds;
  118. [[UIApplication sharedApplication].keyWindow addSubview:show];
  119. }
  120. -(void)setDataDict:(NSDictionary *)dataDict{
  121. self.titleL.text=dataDict[@"title"];
  122. NSString *htmlString =[NSString stringWithFormat:@"%@",dataDict[@"content"]];
  123. // htmlString = [htmlString stringByReplacingOccurrencesOfString:@"\n" withString:@"&nbsp"];
  124. NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData: [htmlString dataUsingEncoding:NSUnicodeStringEncoding] options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes: nil error: nil];
  125. self.textView.attributedText = attributedString;
  126. }
  127. +(void)closeView{
  128. }
  129. -(void)dissmisView{
  130. [self removeFromSuperview];
  131. }
  132. - (void)tongyiBtn:(UIButton *)sender{
  133. [self removeFromSuperview];
  134. }
  135. @end