CNLiveAlertTipView.m 6.25 KB
//
//  CNLiveAlertTipView.m
//  CNLiveCServiceModule
//
//  Created by CNLive on 2021/12/3.
//

#import "CNLiveAlertTipView.h"

@interface CNLiveAlertTipView()
@property (nonatomic, strong)UILabel *titleLabel;
@property (nonatomic, strong)UILabel *messageLabel;
@property (nonatomic, strong)UIButton *cancelBtn;
@property (nonatomic, strong)UIButton *sureBtn;
@property (nonatomic, strong)UIButton *notShowBtn;
@end

@implementation CNLiveAlertTipView

+ (void)showTipsInViewSureBlock:(void (^)(BOOL))sureBlock
{
    CNLiveAlertTipView *tipView = [[CNLiveAlertTipView alloc] initWithFrame:CGRectMake(0, 0, 285, 379.5)];
    tipView.backgroundColor = kWhiteColor;
    tipView.layer.cornerRadius = 10;
    [tipView addSubview:tipView.titleLabel];
    [tipView addSubview:tipView.messageLabel];
    [tipView addSubview:tipView.cancelBtn];
    [tipView addSubview:tipView.sureBtn];
    [tipView addSubview:tipView.notShowBtn];
    tipView.titleLabel.text = @"免责声明";
    [tipView.titleLabel sizeToFit];
    [tipView.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tipView).offset(25);
        make.centerX.mas_equalTo(tipView);
    }];
    tipView.messageLabel.text = @"1、每人每天有5次投票机会,在网家家APP内参与该活动最多可投5票。在微信、QQ等平台参与该活动最多可投3票;投票机会0点重置。\n\n2、本活动禁止刷票,凡是通过非正常手段刷票获取票数的行为,系统检测到并核实后将取消参赛资格。凡是通过非正常手段刷票获取票数的行为,系统检测到并核实后将取消参赛资。";
    [tipView.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tipView.titleLabel.mas_bottom);
        make.width.offset(255);
        make.height.offset(185);
        make.centerX.mas_equalTo(tipView);
    }];
    
    [tipView.cancelBtn setTitle:@"拒绝" forState:UIControlStateNormal];
    [tipView.sureBtn setTitle:@"接受" forState:UIControlStateNormal];
    [tipView.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(tipView).offset(15);
        make.bottom.equalTo(tipView).offset(-20);
        make.width.offset(120);
        make.height.offset(39);
    }];
    [tipView.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(tipView).offset(-15);
        make.bottom.equalTo(tipView.cancelBtn);
        make.width.offset(120);
        make.height.offset(39);
    }];
    [tipView.notShowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(tipView.cancelBtn.mas_top).offset(-10);
        make.width.offset(105);
        make.height.offset(20);
        make.left.equalTo(tipView).offset(15);
    }];
    QMUIModalPresentationViewController *modalViewController = [[QMUIModalPresentationViewController alloc] init];
    modalViewController.contentView = tipView;
    modalViewController.modal = YES;
    [modalViewController showWithAnimated:YES completion:nil];
    __weak typeof(modalViewController) weakModalViewController = modalViewController;
    __weak typeof(tipView) weakTipView = tipView;
    [tipView.cancelBtn addBlockForControlEvents:UIControlEventTouchUpInside block:^(id  _Nonnull sender) {
        [weakModalViewController hideWithAnimated:YES completion:nil];
    }];
    [tipView.sureBtn addBlockForControlEvents:UIControlEventTouchUpInside block:^(id  _Nonnull sender) {
        [weakModalViewController hideWithAnimated:YES completion:^(BOOL finished) {
            if (finished&&sureBlock) {
                sureBlock(weakTipView.notShowBtn.isSelected);
            }
        }];
    }];
}
#pragma mark - Action
-(void)notShowBtnClick:(UIButton *)sender{
    sender.selected = !sender.isSelected;
}
#pragma mark - Getting&&Setting
- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textColor = CNLiveColorWithHexString(@"#333333");
        _titleLabel.font = UIFontMake(17);
    }
    return _titleLabel;
}
-(UILabel *)messageLabel
{
    if (!_messageLabel) {
        _messageLabel = [[UILabel alloc] init];
        _messageLabel.textAlignment = NSTextAlignmentCenter;
        _messageLabel.textColor = CNLiveColorWithHexString(@"#333333");
        _messageLabel.font = UIFontMake(13);
        _messageLabel.numberOfLines = 0;
    }
    return _messageLabel;
}

-(UIButton *)cancelBtn
{
    if (!_cancelBtn) {
        _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_cancelBtn setTitleColor:CNLiveColorWithHexString(@"#999999") forState:UIControlStateNormal];
        _cancelBtn.layer.cornerRadius = 21;
        _cancelBtn.titleLabel.font = UIFontMake(16);
        _cancelBtn.backgroundColor = CNLiveColorWithHexString(@"#EEEEEE");
    }
    return _cancelBtn;
}
-(UIButton *)sureBtn
{
    if (!_sureBtn) {
        _sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_sureBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
        _sureBtn.layer.cornerRadius = 21;
        _sureBtn.titleLabel.font = UIFontMake(16);
        _sureBtn.backgroundColor = [UIColor colorWithPatternImage:[UIImage gradientVerticalImageWithColors:@[CNLiveColorWithHexString(@"#FFAA4A"),CNLiveColorWithHexString(@"#EC5645")] rect:CGRectMake(0, 0, 120, 39)]];
    }
    return _sureBtn;
}

- (UIButton *)notShowBtn
{
    if (!_notShowBtn) {
        _notShowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_notShowBtn setImage:[UIImage loadCServiceBundle:@"tips_no"] forState:UIControlStateNormal];
        [_notShowBtn setImage:[UIImage loadCServiceBundle:@"tips_select"] forState:UIControlStateSelected];
        _notShowBtn.backgroundColor = kClearColor;
        [_notShowBtn setTitle:@"下次不再弹出" forState:UIControlStateNormal];
        [_notShowBtn setTitleColor:CNLiveColorWithHexString(@"#F5A623") forState:UIControlStateNormal];
        [_notShowBtn setTitle:@"下次不再弹出" forState:UIControlStateSelected];
        [_notShowBtn setTitleColor:CNLiveColorWithHexString(@"#F5A623") forState:UIControlStateSelected];
        _notShowBtn.titleLabel.font = UIFontMake(14);
        [_notShowBtn addTarget:self action:@selector(notShowBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _notShowBtn;
}
@end