HaveNoticeView.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //
  2. // HaveNoticeView.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/4/1.
  6. //
  7. #import "HaveNoticeView.h"
  8. @interface HaveNoticeView ()
  9. @end
  10. @implementation HaveNoticeView
  11. static HaveNoticeView * _instance;
  12. + (instancetype)shardInstance {
  13. static dispatch_once_t HaveNoticeViewonceToken;
  14. dispatch_once(&HaveNoticeViewonceToken, ^{
  15. _instance = [[self alloc] init];
  16. });
  17. return _instance;
  18. }
  19. - (id)initWithFrame:(CGRect)frame
  20. {
  21. self = [super initWithFrame:frame];
  22. if (self)
  23. {
  24. //[self drawAnyView];
  25. }
  26. return self;
  27. }
  28. - (void)setCurNoticeModel:(noticeModel *)curNoticeModel
  29. {
  30. _curNoticeModel = curNoticeModel;
  31. [self drawAnyView];
  32. self.isShow = YES;
  33. }
  34. - (void)drawAnyView
  35. {
  36. if(_bgView){
  37. [_bgView removeFromSuperview];
  38. }
  39. self.tag = 111112;
  40. [self setBackgroundColor:HW000000Color60];
  41. BOOL isNeedScroll = NO;
  42. NSString *titleStr = _curNoticeModel.data.title;
  43. NSString *contentStr = _curNoticeModel.data.content;
  44. CGFloat curHeight = [contentStr boundingRectWithSize:CGSizeMake(300 -40, 1000) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.0]} context:nil].size.height;
  45. CGFloat fullHeight = curHeight + 20;
  46. curHeight += 10;
  47. if( (curHeight + 200 +100) >= SCREEN_H){
  48. curHeight = SCREEN_H - 200 - 150;
  49. isNeedScroll = YES;
  50. }
  51. _bgView = [[UIView alloc] init];
  52. [_bgView setBackgroundColor:[UIColor whiteColor]];
  53. [_bgView.layer setCornerRadius:16.f];
  54. [self addSubview:_bgView];
  55. [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.height.mas_equalTo(200.f + curHeight);
  57. make.width.mas_equalTo(300.f);
  58. make.centerX.equalTo(self.mas_centerX);
  59. make.centerY.equalTo(self.mas_centerY);
  60. }];
  61. // 图片
  62. UIImageView *topImageView = [[UIImageView alloc] init];
  63. topImageView.image = [UIImage imageNamed:@"noticeTopBg"];
  64. topImageView.contentMode = UIViewContentModeScaleAspectFit;
  65. [_bgView addSubview:topImageView];
  66. [topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  67. make.top.mas_equalTo(-36);
  68. make.left.mas_equalTo(_bgView.mas_left);
  69. make.right.mas_equalTo(_bgView.mas_right);
  70. make.height.mas_equalTo(179);
  71. }];
  72. /*标题文字*/
  73. UILabel *titleLabel = [[UILabel alloc] init];
  74. [titleLabel setText:titleStr];
  75. [titleLabel setTextColor:[UIColor hwColor:@"#00223E"]];
  76. [titleLabel setFont:[UIFont boldSystemFontOfSize:18.0]];
  77. [titleLabel setTextAlignment:(NSTextAlignmentCenter)];
  78. [_bgView addSubview:titleLabel];
  79. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.top.mas_equalTo(75);
  81. make.left.mas_equalTo(20);
  82. make.right.mas_equalTo(-20);
  83. make.height.mas_equalTo(20);
  84. }];
  85. /*提示文字*/
  86. UILabel *tipsLabel = [[UILabel alloc] init];
  87. //[tipsLabel setText:NSLocalizedString(@"app_update_new_version_tips",nil)];
  88. [tipsLabel setText:contentStr];
  89. [tipsLabel setTextColor:HW0A132BColor];
  90. [tipsLabel setFont:[UIFont systemFontOfSize:14.f]];
  91. //[tipsLabel setTextAlignment:(NSTextAlignmentCenter)];
  92. [tipsLabel setNumberOfLines:0];
  93. //tipsLabel.backgroundColor = [UIColor redColor];
  94. //可能文字超出
  95. UIScrollView *bgScorllV = [[UIScrollView alloc] init];
  96. //bgScorllV.showsHorizontalScrollIndicator = NO;
  97. //bgScorllV.backgroundColor = [UIColor greenColor];
  98. if(isNeedScroll){
  99. [_bgView addSubview:bgScorllV];
  100. [bgScorllV mas_makeConstraints:^(MASConstraintMaker *make) {
  101. make.top.equalTo(titleLabel.mas_bottom).offset(20.f);
  102. make.left.mas_equalTo(0);
  103. make.right.mas_equalTo(0);
  104. make.height.mas_equalTo(curHeight);
  105. }];
  106. [bgScorllV addSubview:tipsLabel];
  107. [tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  108. make.top.mas_equalTo(0);
  109. make.left.mas_equalTo(20);
  110. //make.right.mas_equalTo(-20);
  111. make.width.mas_equalTo(260);
  112. make.height.mas_equalTo(fullHeight);
  113. }];
  114. bgScorllV.contentSize = CGSizeMake(300, fullHeight);
  115. }
  116. else{
  117. [_bgView addSubview:tipsLabel];
  118. [tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  119. make.top.equalTo(titleLabel.mas_bottom).offset(20.f);
  120. make.left.mas_equalTo(20);
  121. make.right.mas_equalTo(-20);
  122. make.height.mas_equalTo(curHeight);
  123. }];
  124. }
  125. UIButton *updatekBtn = [[UIButton alloc] init];
  126. // gradient
  127. CAGradientLayer *gl = [CAGradientLayer layer];
  128. gl.frame = CGRectMake(0,0,240.f,40.f);
  129. gl.startPoint = CGPointMake(0, 0.5);
  130. gl.endPoint = CGPointMake(1, 0.5);
  131. gl.colors = @[(__bridge id)[UIColor hwColor:@"#0BDDFD"].CGColor, (__bridge id)HW058DFBColor.CGColor];
  132. gl.locations = @[@(0), @(1.0f)];
  133. [updatekBtn.layer addSublayer:gl];
  134. [updatekBtn addTarget:self action:@selector(deleteBtnPressed) forControlEvents:(UIControlEventTouchUpInside)];
  135. [updatekBtn setTitle:NSLocalizedString(@"guide_set_pwd_guide_know",nil) forState:(UIControlStateNormal)];
  136. [updatekBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  137. [updatekBtn.titleLabel setFont:[UIFont systemFontOfSize:16.f]];
  138. [updatekBtn.layer setCornerRadius:8.f];
  139. updatekBtn.clipsToBounds = YES;
  140. [_bgView addSubview:updatekBtn];
  141. [updatekBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  142. make.centerX.equalTo(_bgView.mas_centerX);
  143. make.width.mas_equalTo(240.f);
  144. make.bottom.mas_equalTo(-20.f);
  145. make.height.mas_equalTo(40.f);
  146. }];
  147. }
  148. - (void)deleteBtnPressed
  149. {
  150. [self removeFromSuperview];
  151. self.isShow = NO;
  152. if(_curNoticeModel.data.curNoticeId){
  153. [HWDataManager setStringWithKey:Const_did_show_Notice_ID value:_curNoticeModel.data.curNoticeId];
  154. }
  155. if(_closeViewFun){
  156. _closeViewFun();
  157. }
  158. }
  159. @end