| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- //
- // MOTitleNormalAlertView.m
- // MiMoLive
- //
- // Created by SuperC on 2023/11/5.
- //
- #define LBINPUTALERTVIEWHEIGHT 219.0
- #define BtnBottomSpacing 24.0
- #define BtnLeftSpacing 20.0
- #define BtnHeight 36.0
- #define LeftAndRightSpacing 15.0
- #import "MOTitleNormalAlertView.h"
- @interface MOTitleNormalAlertView ()
- /** 背景 */
- @property (nonatomic, strong) UIView *bgView;
- @end
- @implementation MOTitleNormalAlertView
- - (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.twoBtnWidth = SCREENWIDTH * 0.76 / 2.0;
-
- [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(22);
- }];
-
- [self.containerView addSubview:self.closeBtn];
- [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.height.equalTo(@14.0);
- make.top.equalTo(self.containerView).offset(12.0);
- make.right.equalTo(self.containerView).offset(-10.0);
- }];
- self.closeBtn.hidden = YES;
-
- [self.containerView addSubview:self.subTitleLabel];
- [self.subTitleLabel 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.titleLabel.mas_bottom).with.offset(12);
- }];
-
- //取消按钮
- [self.containerView addSubview:self.cancelBtn];
- [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make)
- {
- make.bottom.equalTo(self.containerView).offset(-BtnBottomSpacing);
- make.left.equalTo(self.containerView).offset(BtnLeftSpacing);
- 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(LeftAndRightSpacing);
- make.right.mas_equalTo(-BtnLeftSpacing);
- }];
- }
- - (void)calculateHeight{
- //主标题高度
- CGFloat titleHeight = [MOTools calculateRowHeight:self.titleLabel.text font:self.titleLabel.font andWidth:(SCREENWIDTH * 0.76 - 16.0 * 2)];
-
- CGFloat subTitleHeight = [MOTools calculateRowHeight:self.subTitleLabel.text font:self.subTitleLabel.font andWidth:(SCREENWIDTH * 0.76 - 16.0 * 2)];
-
- CGFloat contentViewHeight = 24.0 + titleHeight + 10.0 + subTitleHeight + 20.0 + BtnHeight + BtnBottomSpacing;
- [self.containerView mas_updateConstraints:^(MASConstraintMaker *make)
- {
- make.height.mas_equalTo(contentViewHeight);
- }];
- }
- #pragma mark - my method
- - (void)setIsSingleBtn:(BOOL)isSingleBtn
- {
- _isSingleBtn = isSingleBtn;
- //单个按钮
- if (isSingleBtn)
- {
- self.confirmBtn.layer.cornerRadius = BtnHeight / 2.0;
-
- [self.confirmBtn mas_remakeConstraints:^(MASConstraintMaker *make)
- {
- make.bottom.equalTo(self.containerView).offset(-BtnBottomSpacing);
- make.left.equalTo(self.containerView).offset(45);
- make.right.equalTo(self.containerView).offset(-45);
- make.height.mas_equalTo(BtnHeight);
- }];
-
- [self.cancelBtn removeFromSuperview];
- }
- }
- - (void)setIsShowCloseBtn:(BOOL)isShowCloseBtn{
- _isShowCloseBtn = isShowCloseBtn;
-
- if(isShowCloseBtn){
- self.closeBtn.hidden = NO;
- }
- }
- - (void)setIsVipTip:(BOOL)isVipTip{
- _isVipTip = isVipTip;
-
- if(isVipTip){
- [self.bgImgView setImage:[UIImage imageNamed:@"icon_vip_buy_tip_bg"]];
- self.containerView.backgroundColor = [UIColor clearColor];
- self.bgImgView.hidden = NO;
-
- self.titleLabel.textColor = [MOTools colorWithHexString:@"#D3B88D" alpha:1.0];
-
- [self.cancelBtn setBackgroundColor:[MOTools colorWithHexString:@"#B0B0B0" alpha:1.0]];
- [self.cancelBtn setTitleColor:[MOTools colorWithHexString:@"#FFFFFF" alpha:1.0] forState:UIControlStateNormal];
-
- [self.confirmBtn setBackgroundColor:[MOTools colorWithHexString:@"#E8C786" alpha:1.0]];
- [self.confirmBtn setTitleColor:[MOTools colorWithHexString:@"#582D1E" alpha:1.0] forState:UIControlStateNormal];
- }
- }
- - (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.confirmBlock)
- {
- self.confirmBlock();
- }
-
- [self dismiss];
- }
- - (void)dismiss//取消掉键盘
- {
- [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];
- }
- }];
-
- self.dismissBlock ? self.dismissBlock() : nil;
- }
- #pragma mark - 懒加载
- - (UIView *)bgView
- {
- if (!_bgView)
- {
- _bgView = [[UIView alloc] init];
- _bgView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bgViewTapClick)];
- [_bgView addGestureRecognizer:tap];
- }
- return _bgView;
- }
- - (void)bgViewTapClick{
-
- if(self.isStrongBg){
- return;
- }
-
- [self dismiss];
- }
- - (UIView *)containerView
- {
- if (!_containerView)
- {
- _containerView = [[UIView alloc] init];
- _containerView.backgroundColor = [MOTools colorWithHexString:@"#FFFFFF"];
- _containerView.layer.masksToBounds = YES;
- _containerView.layer.cornerRadius = 16.0;
- }
- return _containerView;
- }
- - (UILabel *)titleLabel
- {
- if (!_titleLabel)
- {
- _titleLabel = [[UILabel alloc] init];
- _titleLabel.textColor = kBaseTextColor_1;
- _titleLabel.font = [MOTextTools mediumFont:16];
- _titleLabel.textAlignment = NSTextAlignmentCenter;
- _titleLabel.numberOfLines = 0;
- _titleLabel.text = @"";
- }
- return _titleLabel;
- }
- - (UILabel *)subTitleLabel
- {
- if (!_subTitleLabel)
- {
- _subTitleLabel = [[UILabel alloc] init];
- _subTitleLabel.textColor = kBaseTextColor_2;
- _subTitleLabel.textAlignment = NSTextAlignmentCenter;
- _subTitleLabel.font = [MOTextTools regularFont:13];
- _subTitleLabel.numberOfLines = 0;
- }
- return _subTitleLabel;
- }
- - (BigBtn *)cancelBtn
- {
- if (!_cancelBtn)
- {
- _cancelBtn = [[BigBtn alloc] init];
- _cancelBtn.titleLabel.font = [MOTextTools regularFont:16];
- _cancelBtn.layer.borderWidth = 1.0f;
- _cancelBtn.layer.borderColor = [MOTools colorWithHexString:@"#DADCE6"].CGColor;
- [_cancelBtn setBackgroundColor:[MOTools colorWithHexString:@"#FFFFFF" alpha:1.0]];
- _cancelBtn.layer.masksToBounds = YES;
- _cancelBtn.layer.cornerRadius = 12;
- [_cancelBtn setTitle:@"Cancel" forState:UIControlStateNormal];
- [_cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [_cancelBtn setTitleColor:kBaseTextColor_1 forState:UIControlStateNormal];
- }
- return _cancelBtn;
- }
- - (void)cancelBtnClick{
- if (self.cancelBlock)
- {
- self.cancelBlock();
- }
-
- [self dismiss];
- }
- - (BigBtn *)confirmBtn
- {
- if (!_confirmBtn)
- {
- _confirmBtn = [[BigBtn alloc] init];
- _confirmBtn.titleLabel.font = [MOTextTools regularFont:16];
- [_confirmBtn addTarget:self action:@selector(confirmBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [_confirmBtn setTitle:@"Sure" forState:UIControlStateNormal];
- [_confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- _confirmBtn.layer.masksToBounds = YES;
- _confirmBtn.layer.cornerRadius = 12;
- NSArray *colorArr = @[kBaseColorLeft,kBaseColorRight];
- CGFloat btnWidht = ((SCREENWIDTH * 0.76) - BtnLeftSpacing * 2 - LeftAndRightSpacing) / 2;
- UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0,btnWidht, BtnHeight) Colors:colorArr GradientType:0];
- [_confirmBtn setBackgroundImage:image forState:UIControlStateNormal];
- }
- return _confirmBtn;
- }
- - (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;
- }
- - (BigBtn *)closeBtn
- {
- if (!_closeBtn)
- {
- _closeBtn = [[BigBtn alloc] init];
- [_closeBtn setBackgroundImage:[UIImage imageNamed:@"icon_strong_close"] forState:UIControlStateNormal];
- [_closeBtn addTarget:self action:@selector(closeBtnClick) forControlEvents:UIControlEventTouchUpInside];
- }
- return _closeBtn;
- }
- - (void)closeBtnClick{
- [self dismiss];
- }
- @end
|