newerGuideView.m 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. //
  2. // newerGuideView.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/7/20.
  6. //
  7. #import "newerGuideView.h"
  8. @interface newerGuideView ()<UITextViewDelegate>
  9. @property(nonatomic,strong) UILabel*titleLabel;
  10. @end
  11. @implementation newerGuideView
  12. - (id)initWithFrame:(CGRect)frame{
  13. self = [super initWithFrame:frame];
  14. self.backgroundColor = [UIColor hwColor:@"#000000" alpha:0.6];
  15. [self drawAnyView];
  16. return self;
  17. }
  18. -(void)drawAnyView
  19. {
  20. UIView *whiteBgView = [[UIView alloc] init];
  21. whiteBgView.backgroundColor = [UIColor whiteColor];
  22. [self addSubview:whiteBgView];
  23. whiteBgView.layer.cornerRadius = 8;
  24. whiteBgView.layer.masksToBounds = YES;
  25. [whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  26. make.centerX.mas_equalTo(0);
  27. make.width.mas_equalTo(300);
  28. make.height.mas_equalTo(308);
  29. make.centerY.mas_equalTo(0);
  30. }];
  31. UIImageView * imageBgView = [[UIImageView alloc] init];
  32. imageBgView.image = [UIImage imageNamed:@"nas_newerGuide"];
  33. [self addSubview:imageBgView];
  34. [imageBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.centerX.mas_equalTo(0);
  36. make.width.mas_equalTo(300);
  37. make.height.mas_equalTo(162);
  38. make.top.equalTo(whiteBgView.mas_top).offset(-66);
  39. }];
  40. //新手视频
  41. UILabel *titleLabel = [[UILabel alloc] init];
  42. titleLabel.font = [UIFont boldSystemFontOfSize:18.0];
  43. titleLabel.textColor = [UIColor hwColor:@"#151515"];
  44. titleLabel.text = NSLocalizedString(@"NAS_newer_guide_video",nil);
  45. titleLabel.textAlignment = NSTextAlignmentCenter;
  46. [whiteBgView addSubview:titleLabel];
  47. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.height.mas_equalTo(20);
  49. make.left.mas_equalTo(0);
  50. make.right.mas_equalTo(0);
  51. make.centerY.mas_equalTo(-15);
  52. }];
  53. //为您打开新世界的大门
  54. UILabel *title2Label = [[UILabel alloc] init];
  55. title2Label.font = [UIFont systemFontOfSize:14.0];
  56. title2Label.textColor = [UIColor hwColor:@"#0A132B"];
  57. title2Label.text = NSLocalizedString(@"NAS_newer_guide_video_to_world",nil);
  58. title2Label.textAlignment = NSTextAlignmentCenter;
  59. [whiteBgView addSubview:title2Label];
  60. [title2Label mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.height.mas_equalTo(20);
  62. make.left.mas_equalTo(0);
  63. make.right.mas_equalTo(0);
  64. make.top.equalTo(titleLabel.mas_bottom).offset(8);
  65. }];
  66. //您可以在【我的>新手引导】查看操作教程
  67. // UILabel *title3Label = [[UILabel alloc] init];
  68. // title3Label.font = [UIFont systemFontOfSize:14.0];
  69. // title3Label.textColor = [UIColor hwColor:@"#0A132B"];
  70. // //title3Label.text = NSLocalizedString(@"NAS_newer_guide_video_to_world",nil);
  71. // title3Label.textAlignment = NSTextAlignmentCenter;
  72. // [whiteBgView addSubview:title3Label];
  73. //
  74. // [title3Label mas_makeConstraints:^(MASConstraintMaker *make) {
  75. // make.height.mas_equalTo(20);
  76. // make.left.mas_equalTo(0);
  77. // make.right.mas_equalTo(0);
  78. // make.top.equalTo(title2Label.mas_bottom).offset(8);
  79. // }];
  80. UITextView *contentTV = [[UITextView alloc] init];
  81. contentTV.backgroundColor = [UIColor whiteColor];
  82. contentTV.textColor = [UIColor hwColor:@"#0A132B"];
  83. // contentTV.font = [UIFont systemFontOfSize:16.0];
  84. // contentTV.textAlignment = NSTextAlignmentCenter;
  85. contentTV.delegate = self;
  86. contentTV.editable = NO; //必须禁止输入,否则点击将弹出输入键盘
  87. contentTV.scrollEnabled = NO;
  88. [whiteBgView addSubview:contentTV];
  89. [contentTV mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.height.mas_equalTo(50);
  91. make.left.mas_equalTo(0);
  92. make.right.mas_equalTo(0);
  93. make.top.equalTo(title2Label.mas_bottom).offset(8);
  94. }];
  95. // 创建长按手势识别器
  96. UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress)];
  97. // 设置长按手势的最小按压时间
  98. longPress.minimumPressDuration = 0.5; // 2
  99. // 将手势识别器添加到视图上
  100. [contentTV addGestureRecognizer:longPress];
  101. NSString *title1 = NSLocalizedString(@"NAS_newer_guide_video_tip1",nil);
  102. NSString *title2 = NSLocalizedString(@"NAS_newer_guide_video_tip2",nil);
  103. NSString *title3 = NSLocalizedString(@"NAS_newer_guide_video_tip3",nil);
  104. NSString *fullTitle = [[NSString alloc] initWithFormat:@"%@ %@%@",title1,title2,title3];
  105. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:fullTitle];
  106. NSRange redRange = NSMakeRange([fullTitle rangeOfString:title2].location, [fullTitle rangeOfString:title2].length);
  107. UIColor *noteColor =[UIColor hwColor:@"#01B7EA" alpha:1.0];
  108. [attrStr addAttribute:NSForegroundColorAttributeName value:noteColor range:redRange];
  109. [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:NSMakeRange(0, attrStr.length)];
  110. // 设置段落样式以实现水平中间对齐
  111. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  112. paragraphStyle.alignment = NSTextAlignmentCenter; // 水平中间对齐
  113. [attrStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attrStr.length)];
  114. //title3Label.attributedText = attrStr;
  115. [attrStr addAttribute:NSLinkAttributeName
  116. value:@"didclick1://"
  117. range:redRange];
  118. contentTV.attributedText = attrStr;
  119. UIButton *leftbut = [[UIButton alloc] init];
  120. leftbut.tag = 1;
  121. [leftbut addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  122. [leftbut setTitle:NSLocalizedString(@"NAS_newer_guide_not_newer",nil) forState:UIControlStateNormal];
  123. [leftbut setTitleColor:[UIColor hwColor:@"#0A132B"] forState:UIControlStateNormal];
  124. leftbut.titleLabel.font = [UIFont systemFontOfSize:16];
  125. leftbut.backgroundColor = [UIColor hwColor:@"#E3E8F1"];
  126. leftbut.layer.cornerRadius = 8;
  127. [whiteBgView addSubview:leftbut];
  128. [leftbut mas_makeConstraints:^(MASConstraintMaker *make) {
  129. make.left.mas_equalTo(30);
  130. make.width.mas_equalTo(110);
  131. make.height.mas_equalTo(40);
  132. make.bottom.mas_equalTo(-25);
  133. }];
  134. // gradient
  135. CAGradientLayer *gl = [CAGradientLayer layer];
  136. gl.frame = CGRectMake(0,0,110,40);
  137. gl.startPoint = CGPointMake(0.0, 0.5);
  138. gl.endPoint = CGPointMake(1, 0.5);
  139. gl.colors = @[(__bridge id)[UIColor hwColor:@"#0BDDFD"].CGColor, (__bridge id)[UIColor hwColor:@"#048CFB"].CGColor];
  140. gl.locations = @[@(0), @(1.0f)];
  141. UIButton *rightbut = [[UIButton alloc] init];
  142. [rightbut.layer addSublayer:gl];
  143. rightbut.tag = 2;
  144. [rightbut addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  145. [rightbut setTitle:NSLocalizedString(@"NAS_newer_guide_go_see",nil) forState:UIControlStateNormal];
  146. [rightbut setTitleColor:[UIColor hwColor:@"#FFFFFF"] forState:UIControlStateNormal];
  147. rightbut.titleLabel.font = [UIFont systemFontOfSize:16];
  148. rightbut.layer.cornerRadius = 8;
  149. rightbut.layer.masksToBounds = YES;
  150. [whiteBgView addSubview:rightbut];
  151. [rightbut mas_makeConstraints:^(MASConstraintMaker *make) {
  152. make.right.mas_equalTo(-30);
  153. make.width.mas_equalTo(110);
  154. make.height.mas_equalTo(40);
  155. make.bottom.mas_equalTo(-25);
  156. }];
  157. }
  158. #pragma mark ---- textView Delegate ----
  159. - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction
  160. {
  161. if([[URL scheme] isEqualToString:@"didclick1"]){
  162. [self removeFromSuperview];
  163. if(_didClickButtonFun){
  164. _didClickButtonFun(10);
  165. }
  166. return NO;
  167. }
  168. return YES;
  169. }
  170. #pragma mark 拦截长按事件
  171. - (void)longPress{
  172. HLog(@"拦截长按事件")
  173. }
  174. #pragma mark 按钮事件
  175. - (void)didClickButtonFun:(UIButton*)but
  176. {
  177. NSInteger tag = but.tag;
  178. HLog(@"%ld",tag);
  179. [self removeFromSuperview];
  180. if(_didClickButtonFun){
  181. _didClickButtonFun(tag);
  182. }
  183. }
  184. @end