// // newerGuideView.m // 双子星云手机 // // Created by xd h on 2024/7/20. // #import "newerGuideView.h" @interface newerGuideView () @property(nonatomic,strong) UILabel*titleLabel; @end @implementation newerGuideView - (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; self.backgroundColor = [UIColor hwColor:@"#000000" alpha:0.6]; [self drawAnyView]; return self; } -(void)drawAnyView { UIView *whiteBgView = [[UIView alloc] init]; whiteBgView.backgroundColor = [UIColor whiteColor]; [self addSubview:whiteBgView]; whiteBgView.layer.cornerRadius = 8; whiteBgView.layer.masksToBounds = YES; [whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(0); make.width.mas_equalTo(300); make.height.mas_equalTo(308); make.centerY.mas_equalTo(0); }]; UIImageView * imageBgView = [[UIImageView alloc] init]; imageBgView.image = [UIImage imageNamed:@"nas_newerGuide"]; [self addSubview:imageBgView]; [imageBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(0); make.width.mas_equalTo(300); make.height.mas_equalTo(162); make.top.equalTo(whiteBgView.mas_top).offset(-66); }]; //新手视频 UILabel *titleLabel = [[UILabel alloc] init]; titleLabel.font = [UIFont boldSystemFontOfSize:18.0]; titleLabel.textColor = [UIColor hwColor:@"#151515"]; titleLabel.text = NSLocalizedString(@"NAS_newer_guide_video",nil); titleLabel.textAlignment = NSTextAlignmentCenter; [whiteBgView addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(20); make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.centerY.mas_equalTo(-15); }]; //为您打开新世界的大门 UILabel *title2Label = [[UILabel alloc] init]; title2Label.font = [UIFont systemFontOfSize:14.0]; title2Label.textColor = [UIColor hwColor:@"#0A132B"]; title2Label.text = NSLocalizedString(@"NAS_newer_guide_video_to_world",nil); title2Label.textAlignment = NSTextAlignmentCenter; [whiteBgView addSubview:title2Label]; [title2Label mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(20); make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.equalTo(titleLabel.mas_bottom).offset(8); }]; //您可以在【我的>新手引导】查看操作教程 // UILabel *title3Label = [[UILabel alloc] init]; // title3Label.font = [UIFont systemFontOfSize:14.0]; // title3Label.textColor = [UIColor hwColor:@"#0A132B"]; // //title3Label.text = NSLocalizedString(@"NAS_newer_guide_video_to_world",nil); // title3Label.textAlignment = NSTextAlignmentCenter; // [whiteBgView addSubview:title3Label]; // // [title3Label mas_makeConstraints:^(MASConstraintMaker *make) { // make.height.mas_equalTo(20); // make.left.mas_equalTo(0); // make.right.mas_equalTo(0); // make.top.equalTo(title2Label.mas_bottom).offset(8); // }]; UITextView *contentTV = [[UITextView alloc] init]; contentTV.backgroundColor = [UIColor whiteColor]; contentTV.textColor = [UIColor hwColor:@"#0A132B"]; // contentTV.font = [UIFont systemFontOfSize:16.0]; // contentTV.textAlignment = NSTextAlignmentCenter; contentTV.delegate = self; contentTV.editable = NO; //必须禁止输入,否则点击将弹出输入键盘 contentTV.scrollEnabled = NO; [whiteBgView addSubview:contentTV]; [contentTV mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(50); make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.equalTo(title2Label.mas_bottom).offset(8); }]; // 创建长按手势识别器 UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress)]; // 设置长按手势的最小按压时间 longPress.minimumPressDuration = 0.5; // 2 // 将手势识别器添加到视图上 [contentTV addGestureRecognizer:longPress]; NSString *title1 = NSLocalizedString(@"NAS_newer_guide_video_tip1",nil); NSString *title2 = NSLocalizedString(@"NAS_newer_guide_video_tip2",nil); NSString *title3 = NSLocalizedString(@"NAS_newer_guide_video_tip3",nil); NSString *fullTitle = [[NSString alloc] initWithFormat:@"%@ %@%@",title1,title2,title3]; NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:fullTitle]; NSRange redRange = NSMakeRange([fullTitle rangeOfString:title2].location, [fullTitle rangeOfString:title2].length); UIColor *noteColor =[UIColor hwColor:@"#01B7EA" alpha:1.0]; [attrStr addAttribute:NSForegroundColorAttributeName value:noteColor range:redRange]; [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:NSMakeRange(0, attrStr.length)]; // 设置段落样式以实现水平中间对齐 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.alignment = NSTextAlignmentCenter; // 水平中间对齐 [attrStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attrStr.length)]; //title3Label.attributedText = attrStr; [attrStr addAttribute:NSLinkAttributeName value:@"didclick1://" range:redRange]; contentTV.attributedText = attrStr; UIButton *leftbut = [[UIButton alloc] init]; leftbut.tag = 1; [leftbut addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside]; [leftbut setTitle:NSLocalizedString(@"NAS_newer_guide_not_newer",nil) forState:UIControlStateNormal]; [leftbut setTitleColor:[UIColor hwColor:@"#0A132B"] forState:UIControlStateNormal]; leftbut.titleLabel.font = [UIFont systemFontOfSize:16]; leftbut.backgroundColor = [UIColor hwColor:@"#E3E8F1"]; leftbut.layer.cornerRadius = 8; [whiteBgView addSubview:leftbut]; [leftbut mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(30); make.width.mas_equalTo(110); make.height.mas_equalTo(40); make.bottom.mas_equalTo(-25); }]; // gradient CAGradientLayer *gl = [CAGradientLayer layer]; gl.frame = CGRectMake(0,0,110,40); gl.startPoint = CGPointMake(0.0, 0.5); gl.endPoint = CGPointMake(1, 0.5); gl.colors = @[(__bridge id)[UIColor hwColor:@"#0BDDFD"].CGColor, (__bridge id)[UIColor hwColor:@"#048CFB"].CGColor]; gl.locations = @[@(0), @(1.0f)]; UIButton *rightbut = [[UIButton alloc] init]; [rightbut.layer addSublayer:gl]; rightbut.tag = 2; [rightbut addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside]; [rightbut setTitle:NSLocalizedString(@"NAS_newer_guide_go_see",nil) forState:UIControlStateNormal]; [rightbut setTitleColor:[UIColor hwColor:@"#FFFFFF"] forState:UIControlStateNormal]; rightbut.titleLabel.font = [UIFont systemFontOfSize:16]; rightbut.layer.cornerRadius = 8; rightbut.layer.masksToBounds = YES; [whiteBgView addSubview:rightbut]; [rightbut mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-30); make.width.mas_equalTo(110); make.height.mas_equalTo(40); make.bottom.mas_equalTo(-25); }]; } #pragma mark ---- textView Delegate ---- - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction { if([[URL scheme] isEqualToString:@"didclick1"]){ [self removeFromSuperview]; if(_didClickButtonFun){ _didClickButtonFun(10); } return NO; } return YES; } #pragma mark 拦截长按事件 - (void)longPress{ HLog(@"拦截长按事件") } #pragma mark 按钮事件 - (void)didClickButtonFun:(UIButton*)but { NSInteger tag = but.tag; HLog(@"%ld",tag); [self removeFromSuperview]; if(_didClickButtonFun){ _didClickButtonFun(tag); } } @end