PrecautionsView.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // PrecautionsView.m
  3. // jiaPei
  4. //
  5. // Created by EchoShacolee on 2018/4/25.
  6. // Copyright © 2018年 JCZ. All rights reserved.
  7. //
  8. #import "PrecautionsView.h"
  9. @interface PrecautionsView()
  10. @property(copy,nonatomic)NSString *content;
  11. @property(copy,nonatomic)UITextView *textV;
  12. @end
  13. @implementation PrecautionsView
  14. +(PrecautionsView *)showPrecautionsViewWithContent:(NSString *)content{
  15. PrecautionsView *view = [[PrecautionsView alloc]init];
  16. view.content = content;
  17. [view showView];
  18. return view;
  19. }
  20. - (instancetype)init
  21. {
  22. self = [super init];
  23. if (self) {
  24. self.frame = kFrame;
  25. [self layoutAllSubviews];
  26. }
  27. return self;
  28. }
  29. -(void)layoutAllSubviews{
  30. /*创建灰色背景*/
  31. UIView *bgView = [[UIView alloc] initWithFrame:self.bounds];
  32. bgView.backgroundColor = [UIColor colorWithWhite:.01 alpha:.4];
  33. [self addSubview:bgView];
  34. /*添加手势事件,移除View*/
  35. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissContactView)];
  36. [bgView addGestureRecognizer:tapGesture];
  37. /*创建显示内容*/
  38. UITextView *textV = [[UITextView alloc]init];
  39. textV.contentInset = UIEdgeInsetsMake(10, 10, 10, 10);
  40. _textV = textV;
  41. textV.layer.masksToBounds = YES;
  42. textV.layer.cornerRadius = 5;
  43. textV.editable = NO;
  44. textV.text = self.content;
  45. textV.textColor = [UIColor darkGrayColor];
  46. textV.frame = CGRectMake(20, kNavOffSet+20, kSize.width-40, kSize.height-kNavOffSet-20-kSafeAreaBottomHeight-100);
  47. [self addSubview:textV];
  48. UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
  49. [btn setTitle:@"关闭" forState:UIControlStateNormal];
  50. [btn setTitleColor:[UIColor colorWithRed:35/255.0 green:160/255.0 blue:227/255.0 alpha:1] forState:UIControlStateNormal];
  51. [btn.titleLabel setAdjustsFontSizeToFitWidth:YES];
  52. btn.layer.masksToBounds = YES;
  53. btn.layer.cornerRadius = 5;
  54. btn.backgroundColor = [UIColor whiteColor];
  55. btn.frame = CGRectMake(20, kSize.height-95-kSafeAreaBottomHeight, kSize.width-40, 40);
  56. [btn addTarget:self action:@selector(dismissContactView) forControlEvents:UIControlEventTouchUpInside];
  57. [self addSubview:btn];
  58. }
  59. -(void)setContent:(NSString *)content{
  60. if (_content != content) {
  61. _content = content;
  62. // _textV.text = _content;
  63. //设置行间距
  64. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  65. paragraphStyle.lineSpacing = 8;// 字体的行间距
  66. NSDictionary *attributes = @{
  67. NSFontAttributeName:[UIFont systemFontOfSize:15],
  68. NSParagraphStyleAttributeName:paragraphStyle
  69. };
  70. _textV.attributedText = [[NSAttributedString alloc] initWithString:self.content attributes:attributes];
  71. }
  72. }
  73. // 这里加载在了window上
  74. -(void)showView
  75. {
  76. self.alpha = 1.0;
  77. UIWindow * window = [UIApplication sharedApplication].windows[0];
  78. [window addSubview:self];
  79. }
  80. #pragma mark - 手势点击事件,移除View
  81. - (void)dismissContactView{
  82. __weak typeof(self)weakSelf = self;
  83. [UIView animateWithDuration:0.5 animations:^{
  84. weakSelf.alpha = 0;
  85. } completion:^(BOOL finished) {
  86. [weakSelf removeFromSuperview];
  87. }];
  88. }
  89. @end