| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- //
- // MOAddBlackAlertView.m
- // MiMoLive
- //
- // Created by MiMo on 2025/6/24.
- //
- //时长(1=30分钟,2=24小时,3=3天,4=7天,5=永久) ps:新增黑名单时,字段非空
- #define kMOAddBlackAlerViewWidth 295
- #import "MOAddBlackAlertView.h"
- @interface MOAddBlackAlertView ()
- @property (nonatomic, strong) UIView *backgroundView;
- @property (nonatomic, strong) UIView *contentView;
- @property (nonatomic, strong) UILabel *titleLabel;
- @property (nonatomic, strong) UILabel *descLabel;
- @property (nonatomic, strong) UIStackView *stackView;
- @property (nonatomic, strong) UIButton *oneDayButton;
- @property (nonatomic, strong) UIButton *sevenDayButton;
- @property (nonatomic, strong) UIButton *foreverButton;
- @property (nonatomic, strong) UIButton *cancelButton;
- @property (nonatomic, strong) UIButton *confirmButton;
- @property (nonatomic, assign) NSInteger timeIndex;
- @end
- @implementation MOAddBlackAlertView
- - (instancetype)init {
- if (self = [super init]) {
- [self setupUI];
- [self initData];
- }
- return self;
- }
- - (void)initData {
- self.timeIndex = 5;//默认选中永久选项,==5
- self.foreverButton.selected = YES;
- }
- - (void)setupUI {
- [self addSubview:self.backgroundView];
- [self.backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(0);
- }];
-
- [self addSubview:self.contentView];
- [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.mas_equalTo(0);
- make.width.mas_equalTo(kMOAddBlackAlerViewWidth);
- make.height.mas_equalTo(224);
- }];
-
- [self.contentView addSubview:self.titleLabel];
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(24);
- make.centerX.mas_equalTo(0);
- make.height.mas_equalTo(26);
- }];
-
- [self.contentView addSubview:self.descLabel];
- [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.titleLabel.mas_bottom).offset(8);
- make.left.mas_equalTo(20);
- make.right.mas_equalTo(-20);
- }];
-
- [self.contentView addSubview:self.stackView];
- [self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.descLabel.mas_bottom).offset(12);
- make.left.mas_equalTo(20);
- make.right.mas_equalTo(-20);
- make.height.mas_equalTo(28);
- }];
-
- [self.stackView addArrangedSubview:self.oneDayButton];
- [self.stackView addArrangedSubview:self.sevenDayButton];
- [self.stackView addArrangedSubview:self.foreverButton];
-
- [self.contentView addSubview:self.cancelButton];
- [self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(20);
- make.bottom.mas_equalTo(-24);
- make.size.mas_equalTo(CGSizeMake(113, 36));
- }];
-
- [self.contentView addSubview:self.confirmButton];
- [self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(-20);
- make.centerY.equalTo(self.cancelButton);
- make.size.mas_equalTo(CGSizeMake(113, 36));
- }];
- }
- - (void)show {
- UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window;
- [keyWindow addSubview:self];
- self.frame = CGRectMake(0.0, 0.0, SCREENWIDTH, SCREENHEIGHT);
-
- [self updateContentViewHeight];
-
- //动画效果
- self.contentView.transform = CGAffineTransformMakeScale(1.1, 1.1);
- [UIView animateWithDuration:0.2 animations:^ {
- self.contentView.transform = CGAffineTransformMakeScale(1.0, 1.0);
- } completion:nil];
- }
- - (void)updateContentViewHeight {
- CGFloat descHeight = [MOTools getSizeFrom:self.descLabel.text font:self.descLabel.font maxSize:CGSizeMake(kMOAddBlackAlerViewWidth - 40, MAXFLOAT)].height;
- [self.contentView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(descHeight + 170);//170是其他控件和间距的总和
- }];
- }
- - (void)dismiss {
- [UIView animateWithDuration:0.2 animations:^ {
- self.contentView.transform = CGAffineTransformMakeScale(1.1, 1.1);
- self.contentView.alpha = 0.0;
- } completion:^(BOOL finished) {
- if (finished) {
- [self removeFromSuperview];
- }
- }];
- }
- - (void)cancelButtonAction {
- [self dismiss];
- }
- - (void)confirmButtonAction {
- if (self.addBlackConfirmBlock) {
- self.addBlackConfirmBlock(self.timeIndex);
- }
-
- [self dismiss];
- }
- - (void)selectedTimeButton:(UIButton *)button {
- self.oneDayButton.selected = NO;
- self.sevenDayButton.selected = NO;
- self.foreverButton.selected = NO;
-
- self.oneDayButton.layer.borderWidth = 0;
- self.sevenDayButton.layer.borderWidth = 0;
- self.foreverButton.layer.borderWidth = 0;
-
- button.selected = YES;
- self.timeIndex = button.tag;
- button.layer.borderWidth = 1;
- }
- #pragma mark - Lazy
- - (UIView *)backgroundView {
- if (!_backgroundView) {
- _backgroundView = [[UIView alloc] init];
- _backgroundView.backgroundColor = [MOTools colorWithHexString:@"#000000" alpha:0.4];
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)];
- [_backgroundView addGestureRecognizer:tap];
- }
- return _backgroundView;
- }
- - (UIView *)contentView {
- if (!_contentView) {
- _contentView = [[UIView alloc] init];
- _contentView.layer.masksToBounds = YES;
- _contentView.layer.cornerRadius = 16;
- _contentView.backgroundColor = [MOTools colorWithHexString:@"#FFFFFF"];
- }
- return _contentView;
- }
- - (UILabel *)titleLabel {
- if (!_titleLabel) {
- _titleLabel = [[UILabel alloc] init];
- _titleLabel.text = NSLocalString(@"mimo_2_black_title");
- _titleLabel.font = [MOTextTools mediumFont:16];
- _titleLabel.textColor = kBaseTextColor_1;
- _titleLabel.numberOfLines = 0;
- }
- return _titleLabel;
- }
- - (UILabel *)descLabel {
- if (!_descLabel) {
- _descLabel = [[UILabel alloc] init];
- _descLabel.text = NSLocalString(@"mimo_2_black_desc");
- _descLabel.font = [MOTextTools regularFont:13];
- _descLabel.textColor = kBaseTextColor_2;
- _descLabel.numberOfLines = 0;
- }
- return _descLabel;
- }
- - (UIStackView *)stackView {
- if (!_stackView) {
- _stackView = [[UIStackView alloc] init];
- _stackView.axis = UILayoutConstraintAxisHorizontal;
- _stackView.distribution = UIStackViewDistributionFillEqually;
- _stackView.spacing = 15;
- }
- return _stackView;
- }
- - (UIButton *)oneDayButton {
- if (!_oneDayButton) {
- _oneDayButton = [[UIButton alloc] init];
- [_oneDayButton setTitleColor:kBaseTextColor_1 forState:UIControlStateNormal];
- [_oneDayButton setTitleColor:[MOTools colorWithHexString:@"#4363FF"] forState:UIControlStateSelected];
- [_oneDayButton setTitle:NSLocalString(@"mimo_2_black_one_day") forState:UIControlStateNormal];
- _oneDayButton.backgroundColor = [MOTools colorWithHexString:@"#F3F4FA"];
- _oneDayButton.titleLabel.font = [MOTextTools regularFont:12];
- _oneDayButton.layer.masksToBounds = YES;
- _oneDayButton.layer.cornerRadius = 14;
- _oneDayButton.layer.borderColor = [MOTools colorWithHexString:@"#4363FF"].CGColor;
- _oneDayButton.layer.borderWidth = 0.0;
- _oneDayButton.tag = 2;
- [_oneDayButton addTarget:self action:@selector(selectedTimeButton:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _oneDayButton;
- }
- - (UIButton *)sevenDayButton {
- if (!_sevenDayButton) {
- _sevenDayButton = [[UIButton alloc] init];
- [_sevenDayButton setTitleColor:kBaseTextColor_1 forState:UIControlStateNormal];
- [_sevenDayButton setTitleColor:[MOTools colorWithHexString:@"#4363FF"] forState:UIControlStateSelected];
- [_sevenDayButton setTitle:NSLocalString(@"mimo_2_black_seven_day") forState:UIControlStateNormal];
- _sevenDayButton.backgroundColor = [MOTools colorWithHexString:@"#F3F4FA"];
- _sevenDayButton.titleLabel.font = [MOTextTools regularFont:12];
- _sevenDayButton.layer.masksToBounds = YES;
- _sevenDayButton.layer.cornerRadius = 14;
- _sevenDayButton.layer.borderColor = [MOTools colorWithHexString:@"#4363FF"].CGColor;
- _sevenDayButton.layer.borderWidth = 0.0;
- _sevenDayButton.tag = 4;
- [_sevenDayButton addTarget:self action:@selector(selectedTimeButton:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _sevenDayButton;
- }
- - (UIButton *)foreverButton {
- if (!_foreverButton) {
- _foreverButton = [[UIButton alloc] init];
- [_foreverButton setTitleColor:kBaseTextColor_1 forState:UIControlStateNormal];
- [_foreverButton setTitleColor:[MOTools colorWithHexString:@"#4363FF"] forState:UIControlStateSelected];
- [_foreverButton setTitle:NSLocalString(@"mimo_back_pack_permanent") forState:UIControlStateNormal];
- _foreverButton.backgroundColor = [MOTools colorWithHexString:@"#F3F4FA"];
- _foreverButton.titleLabel.font = [MOTextTools regularFont:12];
- _foreverButton.layer.masksToBounds = YES;
- _foreverButton.layer.cornerRadius = 14;
- _foreverButton.layer.borderColor = [MOTools colorWithHexString:@"#4363FF"].CGColor;
- _foreverButton.layer.borderWidth = 1.0;
- _foreverButton.tag = 5;
- [_foreverButton addTarget:self action:@selector(selectedTimeButton:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _foreverButton;
- }
- - (UIButton *)cancelButton {
- if (!_cancelButton) {
- _cancelButton = [[UIButton alloc] init];
- [_cancelButton setTitle:NSLocalString(@"mimo_common_cancel") forState:UIControlStateNormal];
- [_cancelButton setTitleColor:kBaseTextColor_1 forState:UIControlStateNormal];
- _cancelButton.titleLabel.font = [MOTextTools regularFont:16];
- _cancelButton.layer.cornerRadius = 12;
- _cancelButton.layer.masksToBounds = YES;
- _cancelButton.layer.borderColor = [MOTools colorWithHexString:@"#DADCE6"].CGColor;
- _cancelButton.layer.borderWidth = 1;
- [_cancelButton addTarget:self action:@selector(cancelButtonAction) forControlEvents:UIControlEventTouchUpInside];
- }
- return _cancelButton;
- }
- - (UIButton *)confirmButton {
- if (!_confirmButton) {
- _confirmButton = [[UIButton alloc] init];
- [_confirmButton setTitle:NSLocalString(@"mimo_common_confirm") forState:UIControlStateNormal];
- [_confirmButton setTitleColor:[MOTools colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
- _confirmButton.titleLabel.font = [MOTextTools regularFont:16];
- NSArray *colorArr = @[kBaseColorLeft,kBaseColorRight];
- UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, 127, 36) Colors:colorArr GradientType:0];
- [_confirmButton setBackgroundImage:image forState:UIControlStateNormal];
- _confirmButton.layer.cornerRadius = 12;
- _confirmButton.layer.masksToBounds = YES;
- [_confirmButton addTarget:self action:@selector(confirmButtonAction) forControlEvents:UIControlEventTouchUpInside];
- }
- return _confirmButton;
- }
- @end
|