backupsOptionTipView~.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //
  2. // backupsOptionTipView.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/7/25.
  6. //
  7. #import "backupsOptionTipView.h"
  8. @interface backupsOptionTipView ()<UITextViewDelegate>
  9. @end
  10. @implementation backupsOptionTipView
  11. - (id)initWithFrame:(CGRect)frame{
  12. self = [super initWithFrame:frame];
  13. self.backgroundColor = [UIColor hwColor:@"#000000" alpha:0.6];
  14. [self drawAnyView];
  15. return self;
  16. }
  17. -(void)drawAnyView
  18. {
  19. UIView *whiteBgView = [[UIView alloc] init];
  20. whiteBgView.backgroundColor = [UIColor whiteColor];
  21. [self addSubview:whiteBgView];
  22. whiteBgView.layer.cornerRadius = 8;
  23. whiteBgView.layer.masksToBounds = YES;
  24. // [whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  25. // make.centerX.mas_equalTo(0);
  26. // make.width.mas_equalTo(300);
  27. // make.height.mas_equalTo(300);
  28. // make.centerY.mas_equalTo(0);
  29. // }];
  30. //温馨提示
  31. UILabel *titleLabel = [[UILabel alloc] init];
  32. titleLabel.font = [UIFont boldSystemFontOfSize:18.0];
  33. titleLabel.textColor = [UIColor hwColor:@"#151515"];
  34. titleLabel.text = NSLocalizedString(@"File_upload_Record_clear_Tip_title",nil);
  35. titleLabel.textAlignment = NSTextAlignmentCenter;
  36. [whiteBgView addSubview:titleLabel];
  37. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.height.mas_equalTo(25);
  39. make.left.mas_equalTo(0);
  40. make.right.mas_equalTo(0);
  41. make.top.mas_equalTo(20);
  42. }];
  43. UITextView *contentTV = [[UITextView alloc] init];
  44. contentTV.backgroundColor = [UIColor whiteColor];
  45. //contentTV.textColor = HW666666Color;//[UIColor hwColor:@"#151515" alpha:0.5];
  46. // contentTV.font = [UIFont systemFontOfSize:16.0];
  47. // contentTV.textAlignment = NSTextAlignmentCenter;
  48. contentTV.delegate = self;
  49. contentTV.editable = NO; //必须禁止输入,否则点击将弹出输入键盘
  50. contentTV.scrollEnabled = NO;
  51. [whiteBgView addSubview:contentTV];
  52. // 创建长按手势识别器
  53. UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress)];
  54. // 设置长按手势的最小按压时间
  55. longPress.minimumPressDuration = 0.5; // 2
  56. // 将手势识别器添加到视图上
  57. [contentTV addGestureRecognizer:longPress];
  58. NSString *title1 = NSLocalizedString(@"backups_need_read_msg",nil);
  59. NSString *title2 = NSLocalizedString(@"backups_need_read_msg2",nil);
  60. NSString *title3 = NSLocalizedString(@"backups_need_read_msg3",nil);
  61. NSString *title4 = NSLocalizedString(@"backups_need_read_msg4",nil);
  62. NSString *fullTitle = [[NSString alloc] initWithFormat:@"%@%@%@%@",title1,title2,title3,title4];
  63. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:fullTitle];
  64. [attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#151515" alpha:0.5] range:NSMakeRange(0, attrStr.length)];
  65. NSRange redRange = NSMakeRange([fullTitle rangeOfString:title3].location, [fullTitle rangeOfString:title3].length);
  66. UIColor *noteColor =[UIColor hwColor:@"#01B7EA" alpha:1.0];
  67. [attrStr addAttribute:NSForegroundColorAttributeName value:noteColor range:redRange];
  68. [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:NSMakeRange(0, attrStr.length)];
  69. // 设置段落样式以实现水平中间对齐
  70. // NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  71. // paragraphStyle.alignment = NSTextAlignmentCenter; // 水平中间对齐
  72. // [attrStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attrStr.length)];
  73. //title3Label.attributedText = attrStr;
  74. [attrStr addAttribute:NSLinkAttributeName
  75. value:@"didclick1://"
  76. range:redRange];
  77. contentTV.attributedText = attrStr;
  78. //计算高度
  79. CGFloat textHeight = [fullTitle boundingRectWithSize:CGSizeMake(270, 1000) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.0]} context:nil].size.height;
  80. textHeight += 40;
  81. [contentTV mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.height.mas_equalTo(textHeight);
  83. make.left.mas_equalTo(15);
  84. make.right.mas_equalTo(-15);
  85. make.top.equalTo(titleLabel.mas_bottom).offset(10.0);
  86. }];
  87. // gradient
  88. CAGradientLayer *gl = [CAGradientLayer layer];
  89. gl.frame = CGRectMake(0,0,240,40);
  90. gl.startPoint = CGPointMake(0.0, 0.5);
  91. gl.endPoint = CGPointMake(1, 0.5);
  92. gl.colors = @[(__bridge id)[UIColor hwColor:@"#0BDDFD"].CGColor, (__bridge id)[UIColor hwColor:@"#048CFB"].CGColor];
  93. gl.locations = @[@(0), @(1.0f)];
  94. UIButton *rightbut = [[UIButton alloc] init];
  95. [rightbut.layer addSublayer:gl];
  96. rightbut.tag = 1;
  97. [rightbut addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  98. [rightbut setTitle:NSLocalizedString(@"guide_set_pwd_guide_know",nil) forState:UIControlStateNormal];
  99. [rightbut setTitleColor:[UIColor hwColor:@"#FFFFFF"] forState:UIControlStateNormal];
  100. rightbut.titleLabel.font = [UIFont systemFontOfSize:16];
  101. rightbut.layer.cornerRadius = 8;
  102. rightbut.layer.masksToBounds = YES;
  103. [whiteBgView addSubview:rightbut];
  104. [rightbut mas_makeConstraints:^(MASConstraintMaker *make) {
  105. make.right.mas_equalTo(-30);
  106. make.width.mas_equalTo(240);
  107. make.height.mas_equalTo(40);
  108. make.bottom.mas_equalTo(-25);
  109. }];
  110. [whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  111. make.centerX.mas_equalTo(0);
  112. make.width.mas_equalTo(300);
  113. make.height.mas_equalTo(45 + textHeight + 10 + 65 + 20);
  114. make.centerY.mas_equalTo(-20);
  115. }];
  116. }
  117. #pragma mark ---- textView Delegate ----
  118. - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction
  119. {
  120. if([[URL scheme] isEqualToString:@"didclick1"]){
  121. [self removeFromSuperview];
  122. if(_didClickButtonFun){
  123. _didClickButtonFun(10);
  124. }
  125. return NO;
  126. }
  127. return YES;
  128. }
  129. #pragma mark 拦截长按事件
  130. - (void)longPress{
  131. HLog(@"拦截长按事件")
  132. }
  133. #pragma mark 按钮事件
  134. - (void)didClickButtonFun:(UIButton*)but
  135. {
  136. NSInteger tag = but.tag;
  137. HLog(@"%ld",tag);
  138. [self removeFromSuperview];
  139. if(_didClickButtonFun){
  140. _didClickButtonFun(tag);
  141. }
  142. }
  143. @end