cdts/xdts-ios 3/TreeHole/Code/Features/Settings/View/inputInviteCodeAlertView.m

122 lines
5.3 KiB
Mathematica
Raw Normal View History

2023-07-27 09:20:00 +08:00
//
// inputInviteCodeAlertView.m
// TreeHole
//
// Created by on 2022/11/13.
//
#import "inputInviteCodeAlertView.h"
@interface inputInviteCodeAlertView()
@property (nonatomic, strong)UIView* contentView;
@property (nonatomic, strong)UITextField* inputCodeTF;
@end
@implementation inputInviteCodeAlertView
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = HEX_COLOR_A(0x000000, 0.6);
[self addSubview:self.contentView];
self.contentView.transform = CGAffineTransformMakeScale(0.1, 0.1);
[UIView animateWithDuration:0.4 animations:^{
self.contentView.transform = CGAffineTransformMakeScale(1, 1);
} completion:^(BOOL finished) {
}];
}
return self;
}
-(UIView *)contentView{
if (!_contentView) {
_contentView = [[UIView alloc]initWithFrame:CGRectMake(20,(SCREEN_HEIGHT - FIX_SIZE(240))/2.0 - FIX_SIZE(30), SCREEN_WIDTH - 40, FIX_SIZE(240))];
_contentView.layer.cornerRadius = 6;
_contentView.layer.masksToBounds = YES;
_contentView.backgroundColor = HEX_COLOR(0x292247);
UILabel* titleLab = [[UILabel alloc]initWithFrame:CGRectMake(20, FIX_SIZE(20), _contentView.width - 40, FIX_SIZE(20))];
titleLab.text = @"请输入邀请您加入APP的邀请码";
titleLab.textAlignment = NSTextAlignmentLeft;
titleLab.font = MT_FONT_MEDIUM_SIZE(14);
titleLab.textColor = HEX_COLOR(0xFFFFFF);
[_contentView addSubview:titleLab];
UITextField* inputCodeTF = [[UITextField alloc]initWithFrame:CGRectMake(20, titleLab.bottom + FIX_SIZE(30), _contentView.width - 40, FIX_SIZE(38))];
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"请输入邀请码"attributes: @{NSFontAttributeName: [UIFont fontWithName:@"PingFang SC" size: 14],NSForegroundColorAttributeName: [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0]}];
inputCodeTF.attributedPlaceholder = string;
inputCodeTF.textColor = HEX_COLOR(0xFFB902);
inputCodeTF.textAlignment = NSTextAlignmentCenter;
inputCodeTF.font = MT_FONT_MEDIUM_SIZE(14);
inputCodeTF.backgroundColor = HEX_COLOR_A(0xFFFFFF, 0.1);
inputCodeTF.layer.cornerRadius = FIX_SIZE(6);
inputCodeTF.layer.masksToBounds = YES;
[_contentView addSubview:inputCodeTF];
_inputCodeTF = inputCodeTF;
UILabel* tipLab = [[UILabel alloc]initWithFrame:CGRectMake(20, inputCodeTF.bottom + FIX_SIZE(20), _contentView.width - 40, FIX_SIZE(20))];
tipLab.text = @"为防止作弊进入APP后请在1小时填写TA的邀请码";
tipLab.textAlignment = NSTextAlignmentLeft;
tipLab.font = MT_FONT_MEDIUM_SIZE(12);
tipLab.textColor = HEX_COLOR(0xFFFFFF);
[_contentView addSubview:tipLab];
UIButton* cancelBtn = [[UIButton alloc]initWithFrame:CGRectMake(20, _contentView.height - FIX_SIZE(20) - FIX_SIZE(38), FIX_SIZE(114), FIX_SIZE(38))];
[cancelBtn setTitle:@"放弃对接" forState:UIControlStateNormal];
cancelBtn.titleLabel.font = MT_FONT_MEDIUM_SIZE(16);
[cancelBtn setTitleColor:HEX_COLOR(0xFFFFFF) forState:UIControlStateNormal];
cancelBtn.backgroundColor = HEX_COLOR_A(0xFFFFFF, 0.1);
cancelBtn.layer.cornerRadius = cancelBtn.height/2.0;
[cancelBtn addTarget:self action:@selector(cancelBtnClick:) forControlEvents:UIControlEventTouchUpInside];
cancelBtn.layer.masksToBounds = YES;
[_contentView addSubview:cancelBtn];
UIButton* surelBtn = [[UIButton alloc]initWithFrame:CGRectMake(_contentView.width - 20 - FIX_SIZE(114), _contentView.height - FIX_SIZE(20) - FIX_SIZE(38), FIX_SIZE(114), FIX_SIZE(38))];
[surelBtn setTitle:@"确认对接" forState:UIControlStateNormal];
surelBtn.titleLabel.font = MT_FONT_MEDIUM_SIZE(16);
[surelBtn setTitleColor:HEX_COLOR(0x16112F) forState:UIControlStateNormal];
surelBtn.backgroundColor = HEX_COLOR_A(0xFFB902, 1);
surelBtn.layer.cornerRadius = surelBtn.height/2.0;
[surelBtn addTarget:self action:@selector(surelBtnClick:) forControlEvents:UIControlEventTouchUpInside];
surelBtn.layer.masksToBounds = YES;
[_contentView addSubview:surelBtn];
}
return _contentView;
}
-(void)cancelBtnClick:(UIButton*)sender{
[UIView animateWithDuration:0.8 animations:^{
self.alpha = 0.1;
} completion:^(BOOL finished) {
if (finished) {
[self removeFromSuperview];
}
}];
}
-(void)surelBtnClick:(UIButton*)sender{
if (_inputCodeTF.text.length != 6) {
[SVProgressHUD showErrorWithStatus:@"格式错误,无法提交"];
return;
}
[PYHTTPManager postWithPath:@"invitecode" params:@{@"invite_code":_inputCodeTF.text} callback:^(id _Nullable rsp, NSError * _Nullable error) {
if (!error) {
[UIView animateWithDuration:0.4 animations:^{
self.alpha = 0.1;
} completion:^(BOOL finished) {
if (finished) {
[self removeFromSuperview];
[SVProgressHUD showSuccessWithStatus:@"填写成功"];
}
}];
}
}];
}
@end