// // QXAlertView.m // QXLive // // Created by 启星 on 2025/6/3. // #import "QXAlertView.h" #import "QXTimer.h" @interface QXAlertView() @property (nonatomic,strong)UILabel *titleLabel; @property (nonatomic,strong)UILabel *messageLabel; @property (nonatomic,strong)UIButton *cancelBtn; @property (nonatomic,strong)UIButton *commitBtn; @property (nonatomic,strong)QXTimer *timer; @end @implementation QXAlertView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubviews]; } return self; } -(void)initSubviews{ self.backgroundColor = [UIColor whiteColor]; [self addRoundedCornersWithRadius:16]; self.titleLabel = [[UILabel alloc] init]; self.titleLabel.font = [UIFont boldSystemFontOfSize:16]; self.titleLabel.text = QXText(@"提示"); self.titleLabel.textColor = RGB16(0x333333); [self addSubview:self.titleLabel]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self); make.top.equalTo(self).offset(16); make.height.mas_equalTo(24); }]; self.messageLabel = [[UILabel alloc] init]; self.messageLabel.font = [UIFont boldSystemFontOfSize:16]; self.messageLabel.text = QXText(@"确定要删除此评论吗?"); self.messageLabel.textColor = RGB16(0x000000); self.messageLabel.numberOfLines = 0; [self addSubview:self.messageLabel]; [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self); make.left.equalTo(self).offset(16); make.right.equalTo(self).offset(-16); make.centerY.equalTo(self); }]; self.commitBtn = [[UIButton alloc] init]; [self.commitBtn addRoundedCornersWithRadius:21]; self.commitBtn.backgroundColor = QXConfig.themeColor; [self.commitBtn setTitle:QXText(@"确认") forState:(UIControlStateNormal)]; [self.commitBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)]; self.commitBtn.titleLabel.font = [UIFont systemFontOfSize:14]; [self.commitBtn addTarget:self action:@selector(commitAction) forControlEvents:(UIControlEventTouchUpInside)]; [self addSubview:self.commitBtn]; [self.commitBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self).offset(-12); make.height.mas_equalTo(42); make.width.mas_equalTo(ScaleWidth(110)); make.right.mas_equalTo(-20); }]; self.cancelBtn = [[UIButton alloc] init]; [self.cancelBtn addRoundedCornersWithRadius:21]; self.cancelBtn.backgroundColor = RGB16(0xF3F3F3); [self.cancelBtn setTitle:QXText(@"取消") forState:(UIControlStateNormal)]; [self.cancelBtn setTitleColor:RGB16(0x999999) forState:(UIControlStateNormal)]; self.cancelBtn.titleLabel.font = [UIFont systemFontOfSize:14]; [self.cancelBtn addTarget:self action:@selector(cancelAction) forControlEvents:(UIControlEventTouchUpInside)]; [self addSubview:self.cancelBtn]; [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self).offset(-12); make.height.mas_equalTo(42); make.width.mas_equalTo(ScaleWidth(110)); make.left.mas_equalTo(20); }]; } -(void)setType:(QXAlertViewType)type{ _type = type; switch (type) { case QXAlertViewTypeDeleteDynamic: self.messageLabel.text = QXText(@"确定要删除此动态吗?"); break; case QXAlertViewTypeDeleteComment: self.messageLabel.text = QXText(@"确定要删除此评论吗?"); break; case QXAlertViewTypeApplySong: self.messageLabel.text = QXText(@"您将要发起点歌申请"); break; case QXAlertViewTypeAgreeSong: case QXAlertViewTypeAgreePK:{ MJWeakSelf [self.cancelBtn setTitle:QXText(@"拒绝") forState:(UIControlStateNormal)]; [self.commitBtn setTitle:QXText(@"同意") forState:(UIControlStateNormal)]; __block int timeCount = 10; _timer = [QXTimer scheduledTimerWithTimeInterval:1 repeats:YES queue:dispatch_get_main_queue() block:^{ timeCount--; if (timeCount<=0) { [self->_timer invalidate]; [weakSelf cancelAction]; }else{ [self->_cancelBtn setTitle:[NSString stringWithFormat:@"%@(%d)",QXText(@"拒绝"),timeCount] forState:(UIControlStateNormal)]; } }]; } break; case QXAlertViewTypeNoCancel:{ self.cancelBtn.hidden = YES; self.commitBtn.hidden = NO; [self.commitBtn mas_remakeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self).offset(-12); make.height.mas_equalTo(42); make.width.mas_equalTo(ScaleWidth(220)); make.centerX.equalTo(self); }]; } break; default: break; } } -(void)setMessage:(NSString *)message{ self.messageLabel.text = message; } -(void)setTitle:(NSString *)title{ _title = title; self.titleLabel.text = title; } -(void)cancelAction{ if (_timer) { [self->_timer invalidate]; _timer = nil; } MJWeakSelf [[QXGlobal shareGlobal] hideViewBlock:^{ if (weakSelf.cancelBlock) { weakSelf.cancelBlock(); } }]; } -(void)commitAction{ if (_timer) { [self->_timer invalidate]; _timer = nil; } MJWeakSelf [[QXGlobal shareGlobal] hideViewBlock:^{ if (weakSelf.commitBlock) { weakSelf.commitBlock(); } }]; } @end