// // MOTitleAndTefAlertView.m // MiMoLive // // Created by SuperC on 2023/11/5. // #define LBINPUTALERTVIEWHEIGHT 380 #import "MOTitleAndTefAlertView.h" #import "MOPlaceHolderTextView.h" @interface MOTitleAndTefAlertView () /** 背景 */ @property (nonatomic, strong) UIView *bgView; /** 白色弹窗view */ @property (nonatomic, strong) UIView *containerView; /** 背景图 */ @property (nonatomic, strong) UIImageView *bgImgView; /** 标题 */ @property (nonatomic, strong) UILabel *titleLabel; /** 确认 */ @property (nonatomic, strong) BigBtn *confirmBtn; @property (nonatomic, strong) MOPlaceHolderTextView *textView; @property (nonatomic, strong) UILabel *tipLab; @end @implementation MOTitleAndTefAlertView - (instancetype)init { if (self = [super init]) { [self setupUI]; } return self; } - (void)setupUI{ UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window; [keyWindow addSubview:self.bgView]; [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.bottom.right.equalTo(keyWindow); }]; [keyWindow addSubview:self.containerView]; [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(SCREENWIDTH * 0.76); make.centerY.equalTo(keyWindow).with.offset(-100.0); make.centerX.equalTo(keyWindow); make.height.mas_equalTo(LBINPUTALERTVIEWHEIGHT); }]; [self.containerView addSubview:self.bgImgView]; [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.containerView); }]; //标题 [self.containerView addSubview:self.titleLabel]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.containerView).with.offset(16.0); make.right.equalTo(self.containerView).with.offset(-16.0); make.top.equalTo(self.containerView).with.offset(28); }]; //确定Button [self.containerView addSubview:self.confirmBtn]; [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.containerView).offset(55.0); make.right.equalTo(self.containerView).offset(-55.0); make.bottom.equalTo(self.containerView).offset(-20.0); make.height.equalTo(@42.0); }]; NSArray *colorArr = @[kBaseBtnBgColor,kBaseBtnBgColor]; UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, (SCREENWIDTH * 0.76 - 55.0 * 2), 48.0) Colors:colorArr GradientType:0]; [self.confirmBtn setBackgroundImage:image forState:UIControlStateNormal]; //输入框 [self.containerView addSubview:self.textView]; [self.textView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.containerView).with.offset(16); make.right.equalTo(self.containerView).with.offset(-16); make.top.equalTo(self.titleLabel.mas_bottom).with.offset(20); make.bottom.equalTo(self.confirmBtn.mas_top).offset(-20.0); }]; [self.containerView addSubview:self.tipLab]; [self.tipLab mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.textView.mas_right).offset(-10.0); make.bottom.equalTo(self.textView.mas_bottom).offset(-10.0); }]; } - (void)textViewDidChange:(UITextView *)textView{ [self checkStatus]; } ///更新界面文字监听状态 - (void)checkStatus { NSString *text = self.textView.text; NSInteger length = text.length; NSInteger leftLength = 200 - length; self.tipLab.text = [NSString stringWithFormat:@"%ld/200", (long)length]; if (leftLength >= 0) { [self.tipLab setTextColor:[MOTools colorWithHexString:@"#DBAFDF" alpha:1.0]]; } else { [self.tipLab setTextColor:[MOTools colorWithHexString:@"#CCCCCC" alpha:1.0]]; } } - (void)calculateHeight{ //主标题高度 CGFloat titleHeight = [MOTools calculateRowHeight:self.titleLabel.text font:[UIFont boldSystemFontOfSize:19.0] andWidth:(SCREENWIDTH * 0.76 - 16.0 * 2)]; CGFloat contentViewHeight = 20.0 + titleHeight + 20.0 + 180.0 + 20.0 + 48.0 + 20.0; [self.containerView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(contentViewHeight); }]; } - (void)show//界面显示动画 { [self calculateHeight]; UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window; [keyWindow addSubview:self]; //动画效果 self.containerView.transform = CGAffineTransformMakeScale(1.3, 1.3); self.containerView.alpha = 0; [UIView animateWithDuration:0.2 animations:^ { self.containerView.transform = CGAffineTransformMakeScale(1.0, 1.0); self.containerView.alpha = 1; } completion:^(BOOL finished) { }]; } - (void)confirmBtnClick//点击确认 { if(self.textView.text.length > 200){ [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_common_enter_limit")]; } [self.textView resignFirstResponder]; if (![self.textView.text isEmpty])//有输入才dismiss { [self dismiss]; } if (self.confirmBlock) { self.confirmBlock(self.textView.text); } } - (void)dismiss//取消掉键盘 { [self.textView resignFirstResponder]; [UIView animateWithDuration:0.2 animations:^ { self.containerView.transform = CGAffineTransformMakeScale(1.3, 1.3); self.containerView.alpha = 0; } completion:^(BOOL finished) { if (finished) { [self.bgView removeFromSuperview]; [self.containerView removeFromSuperview]; [self removeFromSuperview]; } }]; } #pragma mark - 懒加载 - (UIView *)bgView { if (!_bgView) { _bgView = [[UIView alloc] init]; _bgView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)]; [_bgView addGestureRecognizer:tap]; } return _bgView; } - (UIView *)containerView { if (!_containerView) { _containerView = [[UIView alloc] init]; _containerView.backgroundColor = [UIColor clearColor]; _containerView.layer.masksToBounds = YES; _containerView.layer.cornerRadius = 12.0; } return _containerView; } - (UILabel *)titleLabel { if (!_titleLabel) { _titleLabel = [[UILabel alloc] init]; _titleLabel.textColor = [MOTools colorWithHexString:@"#282828" alpha:1.0];; _titleLabel.font = [MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]; _titleLabel.textAlignment = NSTextAlignmentCenter; _titleLabel.numberOfLines = 0; _titleLabel.text = NSLocalString(@"mimo_family_apply_reason_title"); } return _titleLabel; } - (BigBtn *)confirmBtn { if (!_confirmBtn) { _confirmBtn = [[BigBtn alloc] init]; [_confirmBtn addTarget:self action:@selector(confirmBtnClick) forControlEvents:UIControlEventTouchUpInside]; [_confirmBtn setTitle:NSLocalString(@"mimo_fans_fans_club_create_submit") forState:UIControlStateNormal]; [_confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; _confirmBtn.layer.masksToBounds = YES; _confirmBtn.layer.cornerRadius = 42.0 / 2.0; [_confirmBtn setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]]; } return _confirmBtn; } - (MOPlaceHolderTextView *)textView{ if(!_textView){ _textView = [[MOPlaceHolderTextView alloc] init]; _textView.placeholder = NSLocalString(@"mimo_family_apply_reason_placeholder"); _textView.backgroundColor = [MOTools colorWithHexString:@"#F1FDFF" alpha:1.0]; _textView.font = [MOTextTools getTheFontWithSize:14.0 AndFontName:kNormalContentFontStr]; _textView.textColor = [MOTools colorWithHexString:@"#282828" alpha:1.0]; _textView.layer.cornerRadius = 12.0; _textView.layer.masksToBounds = YES; _textView.layer.borderColor = [MOTools colorWithHexString:@"#17CBEA" alpha:1.0].CGColor; _textView.layer.borderWidth = 0.5; _textView.delegate = self; } return _textView; } - (UILabel *)tipLab { if (!_tipLab) { _tipLab = [[UILabel alloc] init]; _tipLab.textColor = [MOTools colorWithHexString:@"#ABABAB" alpha:1.0];; _tipLab.font = [MOTextTools getTheFontWithSize:14.0 AndFontName:kNormalContentFontStr]; _tipLab.textAlignment = NSTextAlignmentRight; _tipLab.numberOfLines = 0; _tipLab.text = @"0/200"; } return _tipLab; } - (UIImageView *)bgImgView{ if(!_bgImgView){ _bgImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_alert_bg"]]; _bgImgView.contentMode = UIViewContentModeScaleToFill; _bgImgView.backgroundColor = [UIColor clearColor]; } return _bgImgView; } @end