Files
featherVoice/QXLive/Tabbar/弹窗/QXAlertView.m
2025-10-30 00:45:15 +08:00

167 lines
5.7 KiB
Objective-C

//
// 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:{
@weakify(self)
[self.cancelBtn setTitle:QXText(@"拒绝") forState:(UIControlStateNormal)];
[self.commitBtn setTitle:QXText(@"同意") forState:(UIControlStateNormal)];
__block int timeCount = 10;
self.timer = [QXTimer scheduledTimerWithTimeInterval:1 repeats:YES queue:dispatch_get_main_queue() block:^{
@strongify(self);
timeCount--;
if (timeCount<=0) {
[self.timer invalidate];
[self 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 (self.timer) {
[self.timer invalidate];
self.timer = nil;
}
@weakify(self)
[[QXGlobal shareGlobal] hideViewBlock:^{
@strongify(self)
if (self.cancelBlock) {
self.cancelBlock();
}
}];
}
-(void)commitAction{
if (self.timer) {
[self.timer invalidate];
self.timer = nil;
}
@weakify(self)
[[QXGlobal shareGlobal] hideViewBlock:^{
@strongify(self)
if (self.commitBlock) {
self.commitBlock();
}
}];
}
@end