SRTipsView.m 4.5 KB
//
//  SRTipsView.m
//  DreamSleep
//
//  Created by peter on 2022/7/11.
//

#import "SRTipsView.h"

@interface SRTipsView ()
@property (nonatomic, strong) UIView *alertView;
@property (nonatomic, strong) UIImageView *topIV;
@property (nonatomic, strong) UIImageView *midIV;
@property (nonatomic, strong) UILabel *tipsLab;
@property (nonatomic, strong) UIButton *gotBtn;
@property (nonatomic, strong) UIButton *closeBtn;
@end

@implementation SRTipsView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:[UIScreen mainScreen].bounds]) {
        self.dk_backgroundColorPicker = DKColorPickerWithColors(ColorFromHex(0x6F7587), DSClearColor, DSWhite);
        self.backgroundColor = [self.backgroundColor colorWithAlphaComponent:0.6];
        
        [self addSubview:self.alertView];
        [self.alertView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self);
            make.width.equalTo(@280);
            make.height.mas_greaterThanOrEqualTo(100);
        }];
    }
    return self;
}

- (void)showTipsAlertView {
    [DSKeyWindow addSubview:self];
}

- (void)dismissTipsAlertView {
    [self removeFromSuperview];
}

#pragma mark - lazy
- (UIView *)alertView {
    if (!_alertView) {
        _alertView = [UIView new];
        _alertView.dk_backgroundColorPicker = DKColorPickerWithColors(DSWhite, AlertDarkColor, DSWhite);
        [_alertView cornerRadius:23.0];
        
        [_alertView addSubview:self.topIV];
        [_alertView addSubview:self.midIV];
        [_alertView addSubview:self.tipsLab];
        [_alertView addSubview:self.gotBtn];
        [_alertView addSubview:self.closeBtn];
        
        [self.topIV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.equalTo(_alertView);
        }];
        [self.midIV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(_alertView);
            make.top.equalTo(@75);
            
        }];
        [self.tipsLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_alertView).offset(15);
            make.right.equalTo(_alertView).offset(-15);
            make.top.equalTo(self.midIV.mas_bottom).offset(15);
        }];
        [self.gotBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(_alertView);
            make.top.equalTo(self.tipsLab.mas_bottom).offset(30);
            make.bottom.equalTo(_alertView).offset(-24);
            make.size.mas_equalTo(CGSizeMake(155, 40));
        }];
        [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_alertView).offset(15);
            make.right.equalTo(_alertView).offset(-15);
        }];
    }
    return _alertView;
}

- (UIImageView *)topIV {
    if (!_topIV) {
        _topIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg_pop"]];
    }
    return _topIV;
}

- (UIImageView *)midIV {
    if (!_midIV) {
        _midIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic_pop_light"]];
    }
    return _midIV;
}

- (UILabel *)tipsLab {
    if (!_tipsLab) {
        NSString *tips = @"我们无法掌握入睡后的行动,却可以通过睡前30分钟的放松活动帮助放松大脑和身体,从而高效入眠。长期坚持,可有效改善睡眠质量。";
        _tipsLab = [UILabel labWithText:tips font:SysFont(14.0) fit:YES];
        _tipsLab.numberOfLines = 0;
        _tipsLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, ColorFromHexA(0xFFFFFF, .5), DSWhite);
    }
    return _tipsLab;
}

- (UIButton *)gotBtn {
    if (!_gotBtn) {
        WS(weakSelf);
        _gotBtn = [UIButton btnWithTitle:@"我知道了" font:BoldFont(16.0)];
        [_gotBtn cornerRadius:20.0];
        [_gotBtn dk_setBackgroundColorPicker:DKColorPickerWithColors(BrandColor, SubNaviDarkColor, DSWhite)];
        [_gotBtn dk_setTitleColorPicker:DKColorPickerWithColors(DSWhite, DkTitleColor, DSWhite) forState:UIControlStateNormal];
        [_gotBtn addTouchUpInsideHandler:^(NSInteger tag) {
            [weakSelf dismissTipsAlertView];
        }];
    }
    return _gotBtn;
}

- (UIButton *)closeBtn {
    if (!_closeBtn) {
        WS(weakSelf);
        _closeBtn = [UIButton new];
        [_closeBtn dk_setImage:DKImagePickerWithNames(@"dk_home_close", @"home_close", @"home_close") forState:UIControlStateNormal];
        [_closeBtn addTouchUpInsideHandler:^(NSInteger tag) {
            [weakSelf dismissTipsAlertView];
        }];
    }
    return _closeBtn;
}

@end