From 5633fa96fe367480481f553faf31f88b10c2c352 Mon Sep 17 00:00:00 2001 From: fengshuo <963787902@qq.com> Date: Mon, 14 Mar 2022 19:08:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=B9=E6=A1=86=E6=94=AF=E6=8C=81=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E4=B8=80=E4=B8=AA=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Base/UI/TTPopup/Config/TTAlertConfig.h | 10 +++- .../Base/UI/TTPopup/Config/TTAlertConfig.m | 2 + xplan-ios/Base/UI/TTPopup/View/TTAlertView.m | 47 +++++++++++++------ 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/xplan-ios/Base/UI/TTPopup/Config/TTAlertConfig.h b/xplan-ios/Base/UI/TTPopup/Config/TTAlertConfig.h index ca881d44..e43221b0 100644 --- a/xplan-ios/Base/UI/TTPopup/Config/TTAlertConfig.h +++ b/xplan-ios/Base/UI/TTPopup/Config/TTAlertConfig.h @@ -13,8 +13,16 @@ NS_ASSUME_NONNULL_BEGIN -@interface TTAlertConfig : NSObject +typedef NS_ENUM(NSUInteger, TTAlertActionStyle) { + TTAlertActionConfirmStyle = 0, // 只有确定按钮 + TTAlertActionCancelStyle = 1, // 只有取消按钮 + TTAlertActionBothStyle = 2, // 全部按钮 +}; + +@interface TTAlertConfig : NSObject +// 按钮显示风格 +@property (nonatomic, assign) TTAlertActionStyle actionStyle; // 容器背景设置 @property (nonatomic, strong) UIColor *backgroundColor; diff --git a/xplan-ios/Base/UI/TTPopup/Config/TTAlertConfig.m b/xplan-ios/Base/UI/TTPopup/Config/TTAlertConfig.m index 5a9f5918..a13a322f 100644 --- a/xplan-ios/Base/UI/TTPopup/Config/TTAlertConfig.m +++ b/xplan-ios/Base/UI/TTPopup/Config/TTAlertConfig.m @@ -30,6 +30,8 @@ static CGFloat kAlertButtonCornerRadius = 8.f; kAlertTitleFont = 16.f; kAlertCornerRadius = 14.f; kAlertButtonCornerRadius = 19.f; + + _actionStyle = TTAlertActionBothStyle; // title _title = @"";// 标题 diff --git a/xplan-ios/Base/UI/TTPopup/View/TTAlertView.m b/xplan-ios/Base/UI/TTPopup/View/TTAlertView.m index 540e007e..c4e2a93a 100644 --- a/xplan-ios/Base/UI/TTPopup/View/TTAlertView.m +++ b/xplan-ios/Base/UI/TTPopup/View/TTAlertView.m @@ -21,6 +21,7 @@ static CGFloat const kBtnHeight = 38.f; @property (nonatomic, strong) UILabel *messageLabel; // 内容 @property (nonatomic, strong) UIButton *cancelButton; // 取消按钮 @property (nonatomic, strong) UIButton *confirmButton; // 确认按钮 +@property (nonatomic, strong) UIStackView *stackView; @end @@ -39,8 +40,9 @@ static CGFloat const kBtnHeight = 38.f; - (void)initViews { [self addSubview:self.titleLabel]; [self addSubview:self.messageLabel]; - [self addSubview:self.cancelButton]; - [self addSubview:self.confirmButton]; + [self addSubview:self.stackView]; + [self.stackView addSubview:self.cancelButton]; + [self.stackView addSubview:self.confirmButton]; } - (void)initConstraints { @@ -55,19 +57,20 @@ static CGFloat const kBtnHeight = 38.f; make.left.right.mas_equalTo(self).inset(kPadding); }]; - [self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) { - make.height.mas_equalTo(kBtnHeight); - make.right.mas_equalTo(self.mas_centerX).offset(-8); - make.left.mas_equalTo(kPadding); - make.bottom.mas_equalTo(-kPadding); - }]; - - [self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) { - make.height.mas_equalTo(kBtnHeight); - make.left.mas_equalTo(self.mas_centerX).offset(8); - make.right.mas_equalTo(-kPadding); - make.bottom.mas_equalTo(-kPadding); - }]; + [self.stackView mas_makeConstraints:^(MASConstraintMaker *make) { + make.bottom.mas_equalTo(-kPadding); + make.centerX.mas_equalTo(self); + }]; + + [self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) { + make.height.mas_equalTo(kBtnHeight); + make.width.mas_equalTo(self.mas_width).multipliedBy(0.4); + }]; + + [self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) { + make.height.mas_equalTo(kBtnHeight); + make.width.mas_equalTo(self.mas_width).multipliedBy(0.4); + }]; } #pragma mark - Button Events @@ -138,6 +141,9 @@ static CGFloat const kBtnHeight = 38.f; _titleLabel.textColor = config.titleColor; _titleLabel.font = config.titleFont; + self.cancelButton.hidden = config.actionStyle == TTAlertActionConfirmStyle; + self.confirmButton.hidden = config.actionStyle == TTAlertActionCancelStyle; + // cancel button [_cancelButton setTitle:config.cancelButtonConfig.title forState:UIControlStateNormal]; [_cancelButton setTitleColor:config.cancelButtonConfig.titleColor forState:UIControlStateNormal]; @@ -227,4 +233,15 @@ static CGFloat const kBtnHeight = 38.f; return _confirmButton; } +- (UIStackView *)stackView { + if (!_stackView) { + _stackView = [[UIStackView alloc] initWithArrangedSubviews:@[self.cancelButton, self.confirmButton]]; + _stackView.distribution = UIStackViewDistributionFillEqually; + _stackView.alignment = UIStackViewAlignmentCenter; + _stackView.spacing = 16; + } + return _stackView; +} + + @end