123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- //
- // PrecautionsView.m
- // jiaPei
- //
- // Created by EchoShacolee on 2018/4/25.
- // Copyright © 2018年 JCZ. All rights reserved.
- //
- #import "PrecautionsView.h"
- @interface PrecautionsView()
- @property(copy,nonatomic)NSString *content;
- @property(copy,nonatomic)UITextView *textV;
- @end
- @implementation PrecautionsView
- +(PrecautionsView *)showPrecautionsViewWithContent:(NSString *)content{
- PrecautionsView *view = [[PrecautionsView alloc]init];
- view.content = content;
- [view showView];
- return view;
- }
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- self.frame = kFrame;
- [self layoutAllSubviews];
- }
- return self;
- }
- -(void)layoutAllSubviews{
-
- /*创建灰色背景*/
- UIView *bgView = [[UIView alloc] initWithFrame:self.bounds];
- bgView.backgroundColor = [UIColor colorWithWhite:.01 alpha:.4];
- [self addSubview:bgView];
-
- /*添加手势事件,移除View*/
- UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissContactView)];
- [bgView addGestureRecognizer:tapGesture];
-
- /*创建显示内容*/
- UITextView *textV = [[UITextView alloc]init];
- textV.contentInset = UIEdgeInsetsMake(10, 10, 10, 10);
- _textV = textV;
- textV.layer.masksToBounds = YES;
- textV.layer.cornerRadius = 5;
- textV.editable = NO;
- textV.text = self.content;
- textV.textColor = [UIColor darkGrayColor];
- textV.frame = CGRectMake(20, kNavOffSet+20, kSize.width-40, kSize.height-kNavOffSet-20-kSafeAreaBottomHeight-100);
- [self addSubview:textV];
-
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
- [btn setTitle:@"关闭" forState:UIControlStateNormal];
- [btn setTitleColor:[UIColor colorWithRed:35/255.0 green:160/255.0 blue:227/255.0 alpha:1] forState:UIControlStateNormal];
- [btn.titleLabel setAdjustsFontSizeToFitWidth:YES];
- btn.layer.masksToBounds = YES;
- btn.layer.cornerRadius = 5;
- btn.backgroundColor = [UIColor whiteColor];
- btn.frame = CGRectMake(20, kSize.height-95-kSafeAreaBottomHeight, kSize.width-40, 40);
- [btn addTarget:self action:@selector(dismissContactView) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:btn];
- }
- -(void)setContent:(NSString *)content{
- if (_content != content) {
- _content = content;
- // _textV.text = _content;
- //设置行间距
- NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
- paragraphStyle.lineSpacing = 8;// 字体的行间距
-
- NSDictionary *attributes = @{
- NSFontAttributeName:[UIFont systemFontOfSize:15],
- NSParagraphStyleAttributeName:paragraphStyle
- };
- _textV.attributedText = [[NSAttributedString alloc] initWithString:self.content attributes:attributes];
- }
- }
- // 这里加载在了window上
- -(void)showView
- {
- self.alpha = 1.0;
- UIWindow * window = [UIApplication sharedApplication].windows[0];
- [window addSubview:self];
- }
- #pragma mark - 手势点击事件,移除View
- - (void)dismissContactView{
- __weak typeof(self)weakSelf = self;
- [UIView animateWithDuration:0.5 animations:^{
- weakSelf.alpha = 0;
- } completion:^(BOOL finished) {
- [weakSelf removeFromSuperview];
- }];
- }
- @end
|