// // HaveNoticeView.m // 双子星云手机 // // Created by xd h on 2024/4/1. // #import "HaveNoticeView.h" @interface HaveNoticeView () @end @implementation HaveNoticeView static HaveNoticeView * _instance; + (instancetype)shardInstance { static dispatch_once_t HaveNoticeViewonceToken; dispatch_once(&HaveNoticeViewonceToken, ^{ _instance = [[self alloc] init]; }); return _instance; } - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { //[self drawAnyView]; } return self; } - (void)setCurNoticeModel:(noticeModel *)curNoticeModel { _curNoticeModel = curNoticeModel; [self drawAnyView]; self.isShow = YES; } - (void)drawAnyView { if(_bgView){ [_bgView removeFromSuperview]; } self.tag = 111112; [self setBackgroundColor:HW000000Color60]; BOOL isNeedScroll = NO; NSString *titleStr = _curNoticeModel.data.title; NSString *contentStr = _curNoticeModel.data.content; CGFloat curHeight = [contentStr boundingRectWithSize:CGSizeMake(300 -40, 1000) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.0]} context:nil].size.height; CGFloat fullHeight = curHeight + 20; curHeight += 10; if( (curHeight + 200 +100) >= SCREEN_H){ curHeight = SCREEN_H - 200 - 150; isNeedScroll = YES; } _bgView = [[UIView alloc] init]; [_bgView setBackgroundColor:[UIColor whiteColor]]; [_bgView.layer setCornerRadius:16.f]; [self addSubview:_bgView]; [_bgView mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(200.f + curHeight); make.width.mas_equalTo(300.f); make.centerX.equalTo(self.mas_centerX); make.centerY.equalTo(self.mas_centerY); }]; // 图片 UIImageView *topImageView = [[UIImageView alloc] init]; topImageView.image = [UIImage imageNamed:@"noticeTopBg"]; topImageView.contentMode = UIViewContentModeScaleAspectFit; [_bgView addSubview:topImageView]; [topImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(-36); make.left.mas_equalTo(_bgView.mas_left); make.right.mas_equalTo(_bgView.mas_right); make.height.mas_equalTo(179); }]; /*标题文字*/ UILabel *titleLabel = [[UILabel alloc] init]; [titleLabel setText:titleStr]; [titleLabel setTextColor:[UIColor hwColor:@"#00223E"]]; [titleLabel setFont:[UIFont boldSystemFontOfSize:18.0]]; [titleLabel setTextAlignment:(NSTextAlignmentCenter)]; [_bgView addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(75); make.left.mas_equalTo(20); make.right.mas_equalTo(-20); make.height.mas_equalTo(20); }]; /*提示文字*/ UILabel *tipsLabel = [[UILabel alloc] init]; //[tipsLabel setText:NSLocalizedString(@"app_update_new_version_tips",nil)]; [tipsLabel setText:contentStr]; [tipsLabel setTextColor:HW0A132BColor]; [tipsLabel setFont:[UIFont systemFontOfSize:14.f]]; //[tipsLabel setTextAlignment:(NSTextAlignmentCenter)]; [tipsLabel setNumberOfLines:0]; //tipsLabel.backgroundColor = [UIColor redColor]; //可能文字超出 UIScrollView *bgScorllV = [[UIScrollView alloc] init]; //bgScorllV.showsHorizontalScrollIndicator = NO; //bgScorllV.backgroundColor = [UIColor greenColor]; if(isNeedScroll){ [_bgView addSubview:bgScorllV]; [bgScorllV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(titleLabel.mas_bottom).offset(20.f); make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.height.mas_equalTo(curHeight); }]; [bgScorllV addSubview:tipsLabel]; [tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.left.mas_equalTo(20); //make.right.mas_equalTo(-20); make.width.mas_equalTo(260); make.height.mas_equalTo(fullHeight); }]; bgScorllV.contentSize = CGSizeMake(300, fullHeight); } else{ [_bgView addSubview:tipsLabel]; [tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(titleLabel.mas_bottom).offset(20.f); make.left.mas_equalTo(20); make.right.mas_equalTo(-20); make.height.mas_equalTo(curHeight); }]; } UIButton *updatekBtn = [[UIButton alloc] init]; // gradient CAGradientLayer *gl = [CAGradientLayer layer]; gl.frame = CGRectMake(0,0,240.f,40.f); gl.startPoint = CGPointMake(0, 0.5); gl.endPoint = CGPointMake(1, 0.5); gl.colors = @[(__bridge id)[UIColor hwColor:@"#0BDDFD"].CGColor, (__bridge id)HW058DFBColor.CGColor]; gl.locations = @[@(0), @(1.0f)]; [updatekBtn.layer addSublayer:gl]; [updatekBtn addTarget:self action:@selector(deleteBtnPressed) forControlEvents:(UIControlEventTouchUpInside)]; [updatekBtn setTitle:NSLocalizedString(@"guide_set_pwd_guide_know",nil) forState:(UIControlStateNormal)]; [updatekBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)]; [updatekBtn.titleLabel setFont:[UIFont systemFontOfSize:16.f]]; [updatekBtn.layer setCornerRadius:8.f]; updatekBtn.clipsToBounds = YES; [_bgView addSubview:updatekBtn]; [updatekBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(_bgView.mas_centerX); make.width.mas_equalTo(240.f); make.bottom.mas_equalTo(-20.f); make.height.mas_equalTo(40.f); }]; } - (void)deleteBtnPressed { [self removeFromSuperview]; self.isShow = NO; if(_curNoticeModel.data.curNoticeId){ [HWDataManager setStringWithKey:Const_did_show_Notice_ID value:_curNoticeModel.data.curNoticeId]; } if(_closeViewFun){ _closeViewFun(); } } @end