JXMessShowView.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // JXMessShowView.m
  3. // shiku_im
  4. //
  5. // Created by 123 on 2020/6/11.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JXMessShowView.h"
  9. #import "JXRegisterShowView.h"
  10. @interface JXMessShowView()<UITextViewDelegate>
  11. @property (nonatomic,weak)UILabel *timeStr;
  12. @property (nonatomic,weak) JXMessShowView *show;
  13. @end
  14. @implementation JXMessShowView
  15. -(instancetype)initWithFrame:(CGRect)frame{
  16. if (self=[super initWithFrame:frame]) {
  17. UIView *backView=[[UIView alloc]init];
  18. backView.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.3];
  19. [self addSubview:backView];
  20. [backView mas_makeConstraints:^(MASConstraintMaker *make) {
  21. make.top.mas_equalTo(0);
  22. make.left.and.right.mas_equalTo(0);
  23. make.bottom.mas_equalTo(0);
  24. }];
  25. UIView *whiteShowView=[[UIView alloc]init];
  26. whiteShowView.backgroundColor=[UIColor colorWithWhite:1.0 alpha:1.0];
  27. whiteShowView.layer.cornerRadius=15;
  28. whiteShowView.layer.masksToBounds=YES;
  29. [backView addSubview:whiteShowView];
  30. [whiteShowView mas_makeConstraints:^(MASConstraintMaker *make) {
  31. make.centerX.mas_equalTo(backView.mas_centerX);
  32. make.centerY.mas_equalTo(backView.mas_centerY);
  33. make.width.mas_equalTo(JX_SCREEN_WIDTH-100);
  34. make.height.mas_equalTo(JX_SCREEN_HEIGHT/2+40);
  35. }];
  36. UILabel *titleL=[[UILabel alloc]init];
  37. titleL.font=[UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  38. titleL.text=@"紧急通知";
  39. titleL.textAlignment=NSTextAlignmentCenter;
  40. [whiteShowView addSubview:titleL];
  41. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.top.mas_equalTo(15);
  43. make.left.mas_equalTo(30);
  44. make.right.mas_equalTo(-30);
  45. }];
  46. UITextView *textView=[[UITextView alloc]init];
  47. textView.font=[UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  48. [whiteShowView addSubview:textView];
  49. textView.editable=NO;
  50. textView.delegate=self;
  51. self.textView=textView;
  52. [textView mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.top.mas_equalTo(titleL.mas_bottom).mas_equalTo(20);
  54. make.left.mas_equalTo(20);
  55. make.right.mas_equalTo(-20);
  56. make.height.mas_equalTo(JX_SCREEN_HEIGHT/2-95);
  57. }];
  58. UILabel *timeStr=[[UILabel alloc]init];
  59. timeStr.font=[UIFont systemFontOfSize:15 weight:UIFontWeightRegular];
  60. timeStr.text=@"2019";
  61. timeStr.textAlignment=NSTextAlignmentRight;
  62. [whiteShowView addSubview:timeStr];
  63. self.timeStr=timeStr;
  64. [timeStr mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.top.mas_equalTo(textView.mas_bottom);
  66. make.right.mas_equalTo(-10);
  67. make.height.mas_equalTo(18);
  68. }];
  69. UIButton *tongYiBtn=[[UIButton alloc]init];
  70. tongYiBtn.titleLabel.font=[UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  71. [tongYiBtn setTitle:@"知道了" forState:UIControlStateNormal];
  72. [tongYiBtn setTitleColor:kRGBColor51 forState:UIControlStateNormal];
  73. //tongYiBtn.backgroundColor=kRGBColor(227, 89, 89);
  74. //tongYiBtn.layer.borderColor=kRGBColor(246, 246, 246).CGColor;
  75. //tongYiBtn.layer.borderWidth=0.5;
  76. tongYiBtn.layer.cornerRadius=15;
  77. tongYiBtn.layer.masksToBounds=YES;
  78. [whiteShowView addSubview:tongYiBtn];
  79. [tongYiBtn addTarget:self action:@selector(tongyiBtn:) forControlEvents:UIControlEventTouchUpInside];
  80. [tongYiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  81. make.bottom.mas_equalTo(-5);
  82. make.height.mas_equalTo(36);
  83. make.width.mas_equalTo(94);
  84. make.centerX.mas_equalTo(whiteShowView.mas_centerX);
  85. }];
  86. }
  87. return self;
  88. }
  89. -(void)setContentDic:(NSDictionary *)contentDic{
  90. NSString *htmlString =[NSString stringWithFormat:@"%@",contentDic[@"content"]];
  91. NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData: [htmlString dataUsingEncoding:NSUnicodeStringEncoding] options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes: nil error: nil];
  92. self.textView.attributedText = attributedString;
  93. NSString *timeStr = [self timeFormate:[NSString stringWithFormat:@"%@",contentDic[@"createTime"]]];
  94. self.timeStr.text=timeStr;
  95. }
  96. - (NSString *)timeFormate:(NSString *)timeS{
  97. NSTimeInterval time=[timeS doubleValue]+28800;//因为时差问题要加8小时 == 28800 sec
  98. NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time/1000];
  99. //NSLog(@"date:%@",[detaildate description]);
  100. //实例化一个NSDateFormatter对象
  101. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  102. //设定时间格式,这里可以设置成自己需要的格式
  103. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
  104. NSString *currentDateStr = [dateFormatter stringFromDate: detaildate];
  105. return currentDateStr;
  106. }
  107. +(void)showView{
  108. JXRegisterShowView *show=[[JXRegisterShowView alloc]init];
  109. show.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.7];
  110. show.frame=[UIScreen mainScreen].bounds;
  111. [[UIApplication sharedApplication].keyWindow addSubview:show];
  112. }
  113. -(void)dissmisView{
  114. [self removeFromSuperview];
  115. }
  116. - (void)tongyiBtn:(UIButton *)sender{
  117. [g_notify postNotificationName:@"closeShowxxx" object:nil];
  118. [self removeFromSuperview];
  119. [self removeFromSuperview];
  120. }
  121. @end