Files
real-e-party-iOS/YuMi/CustomUI/TTPopup/View/TTNewAlertView.m
2025-10-17 14:52:29 +08:00

116 lines
3.9 KiB
Objective-C

// Created by duoban on 2023/1/9.
#import "TTNewAlertView.h"
@interface TTNewAlertView()
@property (nonatomic,strong) UIView *bgView;
@property (nonatomic,strong) UILabel *messageView;
@property (nonatomic,strong) UIButton *confirmBtn;
@property (nonatomic,strong) UIButton *cancelBtn;
@end
@implementation TTNewAlertView
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
self.backgroundColor = [UIColor clearColor];
[self addSubview:self.bgView];
[self.bgView addSubview:self.messageView];
[self.bgView addSubview:self.confirmBtn];
[self.bgView addSubview:self.cancelBtn];
}
- (void)initSubViewConstraints {
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(310));
make.height.mas_equalTo(kGetScaleWidth(149));
make.center.equalTo(self);
}];
[self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(kGetScaleWidth(110));
make.height.mas_equalTo(kGetScaleWidth(37));
make.leading.mas_equalTo(kGetScaleWidth(31));
make.bottom.mas_equalTo(-kGetScaleWidth(31));
}];
[self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.centerY.equalTo(self.confirmBtn);
make.trailing.mas_equalTo(-kGetScaleWidth(31));
}];
[self.messageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kGetScaleWidth(25));
make.centerX.equalTo(self);
make.leading.trailing.equalTo(self).inset(kGetScaleWidth(10));
}];
}
-(void)setMessage:(NSString *)message{
_message = message;
_messageView.text = message;
}
-(void)confirmAction{
[TTPopup dismiss];
if(self.confirmHandle){
self.confirmHandle();
}
}
-(void)cancelAction{
[TTPopup dismiss];
}
#pragma mark -懒加载
- (UIView *)bgView{
if (!_bgView){
_bgView = [UIView new];
_bgView.backgroundColor = [UIColor whiteColor];
[_bgView setCornerWithLeftTopCorner:kGetScaleWidth(12) rightTopCorner:kGetScaleWidth(12) bottomLeftCorner:kGetScaleWidth(12) bottomRightCorner:kGetScaleWidth(12) size:CGSizeMake(kGetScaleWidth(310), kGetScaleWidth(149))];
}
return _bgView;
}
- (UILabel *)messageView{
if (!_messageView){
_messageView = [[UILabel alloc] init];
_messageView.textAlignment = NSTextAlignmentCenter;
_messageView.numberOfLines = 0;
}
return _messageView;
}
-(UIButton *)confirmBtn{
if (!_confirmBtn){
_confirmBtn = [UIButton new];
[_confirmBtn setTitle:YMLocalizedString(@"TTAlertConfig0") forState:UIControlStateNormal];
_confirmBtn.backgroundColor = UIColorFromRGB(0xE6E6F0);
_confirmBtn.layer.cornerRadius = kGetScaleWidth(37)/2;
_confirmBtn.layer.masksToBounds = YES;
[_confirmBtn addTarget:self action:@selector(confirmAction) forControlEvents:UIControlEventTouchUpInside];
}
return _confirmBtn;
}
-(UIButton *)cancelBtn{
if (!_cancelBtn){
_cancelBtn = [UIButton new];
[_cancelBtn setTitle:YMLocalizedString(@"XPShareView7") forState:UIControlStateNormal];
UIImage *image = [UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor confirmButtonGradientStartColor],[DJDKMIMOMColor confirmButtonGradientMiddleColor],[DJDKMIMOMColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(kGetScaleWidth(110), kGetScaleWidth(37))];
_cancelBtn.backgroundColor = [UIColor colorWithPatternImage:image];
_cancelBtn.layer.cornerRadius = kGetScaleWidth(37)/2;
_cancelBtn.layer.masksToBounds = YES;
[_cancelBtn addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
}
return _cancelBtn;
}
@end