Files
xj-zj-ios/DoctorXinjiang/DoctorXinjiang/Project/HQPopView/HQShowPromptPopView.m
T
2025-07-04 11:20:59 +08:00

135 lines
4.8 KiB
Objective-C

//
// HQShowPromptPopView.m
// healthQuestion
//
// Created by 仁康信息 on 2022/9/28.
//
#import "HQShowPromptPopView.h"
@implementation HQShowPromptPopView
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self createUI];
}
return self;
}
- (void)createUI {
UIView * backView = [[UIView alloc] initWithFrame:self.frame];
backView.backgroundColor = UIColorBackground;
[self addSubview:backView];
UIImageView * popImageView = [[UIImageView alloc] initWithImage:IMAGE_NAMED(@"popCenterImg")];
popImageView.userInteractionEnabled = true;
[backView addSubview:popImageView];
[popImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kRealValue(260));
make.width.mas_equalTo(kScreenWidth - 47);
make.centerX.mas_equalTo(self);
}];
UILabel * titLabel = [[UILabel alloc] init];
titLabel.text = @"提示";
titLabel.textColor = CFontColor1;
titLabel.font = BOLDSYSTEMFONT(16);
titLabel.textAlignment = NSTextAlignmentCenter;
[popImageView addSubview:titLabel];
[titLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kRealValue(107));
make.width.mas_equalTo(popImageView);
make.centerX.mas_equalTo(self);
}];
UILabel * detailLabel = [[UILabel alloc] init];
detailLabel.text = @"本人郑重承诺,认真履行自主防疫责任,填报相关内容全部属实";
detailLabel.textColor = CFontColor1;
detailLabel.font = BOLDSYSTEMFONT(16);
detailLabel.numberOfLines = 2;
detailLabel.textAlignment = NSTextAlignmentCenter;
[popImageView addSubview:detailLabel];
[detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(titLabel.mas_bottom).offset(20);
make.height.mas_equalTo(40);
make.left.mas_equalTo(popImageView.mas_left).offset(50.5);
make.right.mas_equalTo(popImageView.mas_right).offset(-40.5);
}];
UIButton * cancalBtn = [[UIButton alloc] init];
[cancalBtn setTitle:@"取消" forState:UIControlStateNormal];
[cancalBtn setTitleColor:UIColorHex(#394356) forState:UIControlStateNormal];
[cancalBtn addTarget:self action:@selector(cancelClick) forControlEvents: UIControlEventTouchUpInside];
[popImageView addSubview:cancalBtn];
[cancalBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(@0);
make.left.mas_equalTo(popImageView.mas_left).offset(35);
make.height.mas_equalTo(50);
make.width.mas_equalTo((popImageView.width-20)/2);
}];
UIButton * sureBtn = [[UIButton alloc] init];
[sureBtn setTitleColor:UIColorHex(#77849E) forState:UIControlStateNormal];
sureBtn.titleLabel.font = SYSTEMFONT(17);
[popImageView addSubview:sureBtn];
[sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(@0);
make.left.mas_equalTo(cancalBtn.mas_right);
make.height.mas_equalTo(50);
make.width.mas_equalTo(cancalBtn);
}];
__block int timeout=3; //倒计时时间
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
dispatch_source_set_event_handler(_timer, ^{
if(timeout<=0){ //倒计时结束,关闭
dispatch_source_cancel(_timer);
dispatch_async(dispatch_get_main_queue(), ^{
//设置界面的按钮显示 根据自己需求设置
[sureBtn setTitleColor:UIColorMain forState:UIControlStateNormal];
[sureBtn setTitle:@"确定" forState:UIControlStateNormal];
[sureBtn addTarget:self action:@selector(cancelClick) forControlEvents:UIControlEventTouchUpInside];
sureBtn.userInteractionEnabled = YES;
});
}else{
int seconds = timeout;
NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
dispatch_async(dispatch_get_main_queue(), ^{
//让按钮变为不可点击的灰色
sureBtn.userInteractionEnabled = NO;
//设置界面的按钮显示 根据自己需求设置
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[sureBtn setTitle:[NSString stringWithFormat:@"%@秒后点击确认",strTime] forState:UIControlStateNormal];
[UIView commitAnimations];
});
timeout--;
}
});
dispatch_resume(_timer);
}
- (void)cancelClick {
[self removeFromSuperview];
}
@end