HaveNoticeView.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. NSString *titleStr = _curNoticeModel.data.title;
  42. NSString *contentStr = _curNoticeModel.data.content;
  43. CGFloat curHeight = [contentStr boundingRectWithSize:CGSizeMake(300 -40, 1000) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.0]} context:nil].size.height;
  44. curHeight += 10;
  45. if( (curHeight + 200) >= SCREEN_H){
  46. curHeight = SCREEN_H - 200 - 10;
  47. }
  48. _bgView = [[UIView alloc] init];
  49. [_bgView setBackgroundColor:[UIColor whiteColor]];
  50. [_bgView.layer setCornerRadius:16.f];
  51. [self addSubview:_bgView];
  52. [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.height.mas_equalTo(200.f + curHeight);
  54. make.width.mas_equalTo(300.f);
  55. make.centerX.equalTo(self.mas_centerX);
  56. make.centerY.equalTo(self.mas_centerY);
  57. }];
  58. // 图片
  59. UIImageView *topImageView = [[UIImageView alloc] init];
  60. topImageView.image = [UIImage imageNamed:@"noticeTopBg"];
  61. topImageView.contentMode = UIViewContentModeScaleAspectFit;
  62. [_bgView addSubview:topImageView];
  63. [topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.top.mas_equalTo(-36);
  65. make.left.mas_equalTo(_bgView.mas_left);
  66. make.right.mas_equalTo(_bgView.mas_right);
  67. make.height.mas_equalTo(179);
  68. }];
  69. /*标题文字*/
  70. UILabel *titleLabel = [[UILabel alloc] init];
  71. [titleLabel setText:titleStr];
  72. [titleLabel setTextColor:[UIColor hwColor:@"#00223E"]];
  73. [titleLabel setFont:[UIFont boldSystemFontOfSize:18.0]];
  74. [titleLabel setTextAlignment:(NSTextAlignmentCenter)];
  75. [_bgView addSubview:titleLabel];
  76. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.top.mas_equalTo(75);
  78. make.left.mas_equalTo(20);
  79. make.right.mas_equalTo(-20);
  80. make.height.mas_equalTo(20);
  81. }];
  82. /*提示文字*/
  83. UILabel *tipsLabel = [[UILabel alloc] init];
  84. //[tipsLabel setText:NSLocalizedString(@"app_update_new_version_tips",nil)];
  85. [tipsLabel setText:contentStr];
  86. [tipsLabel setTextColor:HW0A132BColor];
  87. [tipsLabel setFont:[UIFont systemFontOfSize:14.f]];
  88. //[tipsLabel setTextAlignment:(NSTextAlignmentCenter)];
  89. [tipsLabel setNumberOfLines:0];
  90. [_bgView addSubview:tipsLabel];
  91. [tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.top.equalTo(titleLabel.mas_bottom).offset(20.f);
  93. make.left.mas_equalTo(20);
  94. make.right.mas_equalTo(-20);
  95. make.height.mas_equalTo(curHeight);
  96. }];
  97. UIButton *updatekBtn = [[UIButton alloc] init];
  98. // gradient
  99. CAGradientLayer *gl = [CAGradientLayer layer];
  100. gl.frame = CGRectMake(0,0,240.f,40.f);
  101. gl.startPoint = CGPointMake(0, 0.5);
  102. gl.endPoint = CGPointMake(1, 0.5);
  103. gl.colors = @[(__bridge id)[UIColor hwColor:@"#0BDDFD"].CGColor, (__bridge id)HW058DFBColor.CGColor];
  104. gl.locations = @[@(0), @(1.0f)];
  105. [updatekBtn.layer addSublayer:gl];
  106. [updatekBtn addTarget:self action:@selector(deleteBtnPressed) forControlEvents:(UIControlEventTouchUpInside)];
  107. [updatekBtn setTitle:NSLocalizedString(@"guide_set_pwd_guide_know",nil) forState:(UIControlStateNormal)];
  108. [updatekBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  109. [updatekBtn.titleLabel setFont:[UIFont systemFontOfSize:16.f]];
  110. [updatekBtn.layer setCornerRadius:8.f];
  111. updatekBtn.clipsToBounds = YES;
  112. [_bgView addSubview:updatekBtn];
  113. [updatekBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  114. make.centerX.equalTo(_bgView.mas_centerX);
  115. make.width.mas_equalTo(240.f);
  116. make.bottom.mas_equalTo(-20.f);
  117. make.height.mas_equalTo(40.f);
  118. }];
  119. }
  120. - (void)deleteBtnPressed
  121. {
  122. [self removeFromSuperview];
  123. self.isShow = NO;
  124. if(_curNoticeModel.data.curNoticeId){
  125. [HWDataManager setStringWithKey:Const_did_show_Notice_ID value:_curNoticeModel.data.curNoticeId];
  126. }
  127. if(_closeViewFun){
  128. _closeViewFun();
  129. }
  130. }
  131. @end