2025-08-08 10:49:36 +08:00
|
|
|
//
|
|
|
|
|
// 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:{
|
2025-10-30 00:45:15 +08:00
|
|
|
@weakify(self)
|
2025-08-08 10:49:36 +08:00
|
|
|
[self.cancelBtn setTitle:QXText(@"拒绝") forState:(UIControlStateNormal)];
|
|
|
|
|
[self.commitBtn setTitle:QXText(@"同意") forState:(UIControlStateNormal)];
|
|
|
|
|
__block int timeCount = 10;
|
2025-10-30 00:45:15 +08:00
|
|
|
self.timer = [QXTimer scheduledTimerWithTimeInterval:1 repeats:YES queue:dispatch_get_main_queue() block:^{
|
|
|
|
|
@strongify(self);
|
2025-08-08 10:49:36 +08:00
|
|
|
timeCount--;
|
|
|
|
|
if (timeCount<=0) {
|
2025-10-30 00:45:15 +08:00
|
|
|
[self.timer invalidate];
|
|
|
|
|
[self cancelAction];
|
2025-08-08 10:49:36 +08:00
|
|
|
}else{
|
2025-10-30 00:45:15 +08:00
|
|
|
[self.cancelBtn setTitle:[NSString stringWithFormat:@"%@(%d)",QXText(@"拒绝"),timeCount] forState:(UIControlStateNormal)];
|
2025-08-08 10:49:36 +08:00
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
break;
|
2025-10-20 09:43:10 +08:00
|
|
|
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;
|
2025-08-08 10:49:36 +08:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
-(void)setMessage:(NSString *)message{
|
|
|
|
|
self.messageLabel.text = message;
|
|
|
|
|
}
|
|
|
|
|
-(void)setTitle:(NSString *)title{
|
|
|
|
|
_title = title;
|
|
|
|
|
self.titleLabel.text = title;
|
|
|
|
|
}
|
|
|
|
|
-(void)cancelAction{
|
2025-10-30 00:45:15 +08:00
|
|
|
if (self.timer) {
|
|
|
|
|
[self.timer invalidate];
|
|
|
|
|
self.timer = nil;
|
2025-08-08 10:49:36 +08:00
|
|
|
}
|
2025-10-30 00:45:15 +08:00
|
|
|
@weakify(self)
|
2025-08-08 10:49:36 +08:00
|
|
|
[[QXGlobal shareGlobal] hideViewBlock:^{
|
2025-10-30 00:45:15 +08:00
|
|
|
@strongify(self)
|
|
|
|
|
if (self.cancelBlock) {
|
|
|
|
|
self.cancelBlock();
|
2025-08-08 10:49:36 +08:00
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
-(void)commitAction{
|
2025-10-30 00:45:15 +08:00
|
|
|
if (self.timer) {
|
|
|
|
|
[self.timer invalidate];
|
|
|
|
|
self.timer = nil;
|
2025-08-08 10:49:36 +08:00
|
|
|
}
|
2025-10-30 00:45:15 +08:00
|
|
|
@weakify(self)
|
2025-08-08 10:49:36 +08:00
|
|
|
[[QXGlobal shareGlobal] hideViewBlock:^{
|
2025-10-30 00:45:15 +08:00
|
|
|
@strongify(self)
|
|
|
|
|
if (self.commitBlock) {
|
|
|
|
|
self.commitBlock();
|
2025-08-08 10:49:36 +08:00
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
@end
|