| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- //
- // LBInputAlertView.m
- // LoveBaby_Parents
- //
- // Created by apple on 2018/5/23.
- // Copyright © 2018年 onecloud.ltd. All rights reserved.
- //
- #import "LBInputAlertView.h"
- #import "LBTextField.h"
- #import "BigBtn.h"
- #define LBINPUTALERTVIEWHEIGHT 219
- #define BtnHeight 32.0
- @interface LBInputAlertView ()
- /** 背景 */
- @property (nonatomic, strong) UIView *bgView;
- /** 白色弹窗view */
- @property (nonatomic, strong) UIView *containerView;
- /** 标题 */
- @property (nonatomic, strong) UILabel *titleLabel;
- /** 横线 */
- @property (nonatomic, strong) UIView *hLineView;
- /** 竖线 */
- @property (nonatomic, strong) UIView *vLineView;
- /** 取消 */
- @property (nonatomic, strong) BigBtn *cancelBtn;
- /** 确认 */
- @property (nonatomic, strong) BigBtn *confirmBtn;
- @end
- @implementation LBInputAlertView
- - (instancetype)init
- {
- if (self = [super init])
- {
- [self setupUI];
- }
- return self;
- }
- - (void)setupUI///<设置UI
- {
- 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(29.5);
- make.right.equalTo(self.containerView).with.offset(-27.5);
- make.top.equalTo(self.containerView).with.offset(28);
- }];
-
- //输入框
- [self.containerView addSubview:self.inputField];
- [self.inputField mas_makeConstraints:^(MASConstraintMaker *make)
- {
- make.left.equalTo(self.containerView).with.offset(22);
- make.right.equalTo(self.containerView).with.offset(-22);
- make.top.equalTo(self.titleLabel.mas_bottom).with.offset(20);
- make.height.mas_equalTo(40);
- }];
-
- //横线 (根据新UI 已经隐藏, 有需要放出)
- [self.containerView addSubview:self.hLineView];
- [self.hLineView mas_makeConstraints:^(MASConstraintMaker *make)
- {
- make.height.mas_equalTo(0.5);
- make.left.right.equalTo(self.containerView);
- make.bottom.equalTo(self.containerView).with.offset(-60);
- }];
-
- //竖线 (根据新UI 已经隐藏, 有需要放出)
- [self.containerView addSubview:self.vLineView];
- [self.vLineView mas_makeConstraints:^(MASConstraintMaker *make)
- {
- make.width.mas_equalTo(0.5);
- make.top.equalTo(self.hLineView.mas_bottom);
- make.bottom.equalTo(self.containerView);
- make.centerX.equalTo(self.containerView);
- }];
-
- self.hLineView.hidden = YES;
- self.vLineView.hidden = YES;
-
- //取消按钮
- [self.containerView addSubview:self.cancelBtn];
- [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make)
- {
- make.top.equalTo(self.hLineView.mas_bottom);
- make.left.equalTo(self.containerView).offset(22.0f);
- make.height.mas_equalTo(BtnHeight);
- }];
-
- //确定Button
- [self.containerView addSubview:self.confirmBtn];
- [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make)
- {
- make.height.equalTo(self.cancelBtn);
- make.width.equalTo(self.cancelBtn);
- make.top.equalTo(self.cancelBtn);
- make.left.equalTo(self.cancelBtn.mas_right).offset(20);
- make.right.mas_equalTo(-22);
- }];
-
- // CGFloat btnWidth = (SCREENWIDTH * 0.76 - 22.0 * 2.0 - 20.0) / 2.0;
- // NSArray *colorArr = @[[MOTools colorWithHexString:@"#FF62EE" alpha:1.0],[MOTools colorWithHexString:@"#9923FF" alpha:1.0]];
- // UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, btnWidth, BtnHeight) Colors:colorArr GradientType:0];
- // [self.confirmBtn setBackgroundImage:image forState:UIControlStateNormal];
- }
- #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 = [MOTools colorWithHexString:@"#F8F9FC" alpha:1.0];
- _containerView.layer.masksToBounds = YES;
- _containerView.layer.cornerRadius = 16.0;
- }
- return _containerView;
- }
- - (UILabel *)titleLabel
- {
- if (!_titleLabel)
- {
- _titleLabel = [[UILabel alloc] init];
- _titleLabel.textColor = [MOTools colorWithHexString:@"#737373" alpha:1.0];;
- _titleLabel.font = [MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr];
- _titleLabel.textAlignment = NSTextAlignmentCenter;
- _titleLabel.numberOfLines = 0;
- }
- return _titleLabel;
- }
- - (UITextField *)inputField
- {
- if (!_inputField)
- {
- _inputField = [[LBTextField alloc] init];
- _inputField.textColor = [MOTools colorWithHexString:@"#282828" alpha:1.0];
- _inputField.font = [MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalContentFontStr];
- _inputField.backgroundColor = [UIColor clearColor];
- _inputField.layer.masksToBounds = YES;
- _inputField.layer.cornerRadius = 12.0;
- _inputField.layer.borderColor = [MOTools colorWithHexString:@"#ABABAB" alpha:1.0].CGColor;
- _inputField.layer.borderWidth = 0.5;
- }
- return _inputField;
- }
- - (UIView *)hLineView
- {
- if (!_hLineView)
- {
- _hLineView = [[UIView alloc] init];
- _hLineView.backgroundColor = [MOTools colorWithHexString:@"#EEEEEE" alpha:1.0];
- _hLineView.hidden = YES;
- }
- return _hLineView;
- }
- - (UIView *)vLineView
- {
- if (!_vLineView)
- {
- _vLineView = [[UIView alloc] init];
- _vLineView.backgroundColor = [MOTools colorWithHexString:@"#EEEEEE" alpha:1.0];
- _vLineView.hidden = YES;
- }
- return _vLineView;
- }
- - (BigBtn *)cancelBtn
- {
- if (!_cancelBtn)
- {
- _cancelBtn = [[BigBtn alloc] init];
- _cancelBtn.titleLabel.font = [MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr];
- _cancelBtn.layer.borderWidth = 1.0f;
- UIColor *baseColor = [MOTools colorWithHexString:@"#FFFFFF" alpha:1.0];
- _cancelBtn.layer.borderColor = baseColor.CGColor;
- _cancelBtn.layer.masksToBounds = YES;
- _cancelBtn.layer.cornerRadius = BtnHeight / 2.0;
- [_cancelBtn setTitle:NSLocalString(@"mimo_Cancel") forState:UIControlStateNormal];
- [_cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [_cancelBtn setTitleColor:baseColor forState:UIControlStateNormal];
- _cancelBtn.backgroundColor = [MOTools colorWithHexString:@"#B0B0B0" alpha:1.0];
- }
- return _cancelBtn;
- }
- - (BigBtn *)confirmBtn
- {
- if (!_confirmBtn)
- {
- _confirmBtn = [[BigBtn alloc] init];
- _confirmBtn.titleLabel.font = [MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr];
- [_confirmBtn addTarget:self action:@selector(confirmBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [_confirmBtn setTitle:NSLocalString(@"mimo_TipConfirm") forState:UIControlStateNormal];
- [_confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- _confirmBtn.layer.masksToBounds = YES;
- _confirmBtn.layer.cornerRadius = BtnHeight / 2.0;
- _confirmBtn.backgroundColor = kBaseBtnBgColor;
- }
- return _confirmBtn;
- }
- #pragma mark - my method
- - (void)setPlaceholder:(NSString *)placeholder
- {
- _placeholder = placeholder;
- self.inputField.placeholder = placeholder;
- }
- - (void)setTitleText:(NSString *)titleText//设置标题
- {
- _titleText = titleText;
- self.titleLabel.text = titleText;
- }
- - (void)setLeftBtnTitle:(NSString *)leftBtnTitle//设置左边按钮文字
- {
- [self.cancelBtn setTitle:leftBtnTitle forState:UIControlStateNormal];
- }
- - (void)setRightBtnTitle:(NSString *)rightBtnTitle//设置右边按钮文字
- {
- [self.confirmBtn setTitle:rightBtnTitle forState:UIControlStateNormal];
- }
- - (void)setTitleColor:(UIColor *)titleColor//设置标题颜色
- {
- self.titleLabel.textColor = titleColor;
- }
- - (void)setLeftBtnColor:(UIColor *)leftBtnColor//设置左边按钮颜色
- {
- [self.cancelBtn setTitleColor:leftBtnColor forState:UIControlStateNormal];
- }
- - (void)setRightBtnColor:(UIColor *)rightBtnColor//设置右边按钮颜色
- {
- [self.confirmBtn setTitleColor:rightBtnColor forState:UIControlStateNormal];
- }
- - (void)setShowAccessoryView:(BOOL)showAccessoryView
- {
- _showAccessoryView = showAccessoryView;
- if (showAccessoryView)
- {
- // UIButton *scanBtn = [[UIButton alloc] init];
- // [scanBtn setImage:[UIImage imageNamed:@"saoma"] forState:UIControlStateNormal];
- // scanBtn.frame = CGRectMake(0, 0, 40, 22);
- // self.inputField.rightView = scanBtn;
- // self.inputField.rightViewMode = UITextFieldViewModeAlways;
- // [scanBtn addTarget:self action:@selector(scanBtnClick) forControlEvents:UIControlEventTouchUpInside];
- }
- }
- - (void)scanBtnClick
- {
- [self.inputField resignFirstResponder];
- if (self.accessoryBlock)
- {
- self.accessoryBlock();
- }
- }
- - (void)cancelBtnClick//点击取消
- {
- [self dismiss];
- }
- - (void)confirmBtnClick//点击确认
- {
- [self.inputField resignFirstResponder];
- if (![self.inputField.text isEmpty])//有输入才dismiss
- {
- [self dismiss];
- }
- if (self.confirmBlock)
- {
- self.confirmBlock(self.inputField.text);
- }
- }
- - (void)show//界面显示动画
- {
- 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)
- {
- [self.inputField becomeFirstResponder];
- }];
- }
- - (void)dismiss//取消掉键盘
- {
- [self.inputField 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];
- }
- }];
- }
- - (void)setNeedHide:(BOOL)needHide
- {
- if (needHide)
- {
- self.bgView.hidden = YES;
- self.containerView.hidden = YES;
- self.hidden = YES;
- }
- else
- {
- self.bgView.hidden = NO;
- self.containerView.hidden = NO;
- self.hidden = NO;
- }
- }
- - (UIImageView *)bgImgView{
- if(!_bgImgView){
- _bgImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_alert_bg"]];
- _bgImgView.contentMode = UIViewContentModeScaleToFill;
- _bgImgView.backgroundColor = [UIColor clearColor];
- _bgImgView.hidden = YES;
- }
- return _bgImgView;
- }
- @end
|