弹框支持显示一个按钮
This commit is contained in:
@@ -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;
|
||||
|
||||
|
@@ -31,6 +31,8 @@ static CGFloat kAlertButtonCornerRadius = 8.f;
|
||||
kAlertCornerRadius = 14.f;
|
||||
kAlertButtonCornerRadius = 19.f;
|
||||
|
||||
_actionStyle = TTAlertActionBothStyle;
|
||||
|
||||
// title
|
||||
_title = @"";// 标题
|
||||
_titleFont = [UIFont fontWithName:@"PingFangSC-Medium" size:kAlertTitleFont];// 字体
|
||||
|
@@ -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,18 +57,19 @@ static CGFloat const kBtnHeight = 38.f;
|
||||
make.left.right.mas_equalTo(self).inset(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.right.mas_equalTo(self.mas_centerX).offset(-8);
|
||||
make.left.mas_equalTo(kPadding);
|
||||
make.bottom.mas_equalTo(-kPadding);
|
||||
make.width.mas_equalTo(self.mas_width).multipliedBy(0.4);
|
||||
}];
|
||||
|
||||
[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);
|
||||
make.width.mas_equalTo(self.mas_width).multipliedBy(0.4);
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
Reference in New Issue
Block a user